Repository navigation
Answer a cut that leaves no whole file part with the limit, not "Field required" - #480
SamikaPerera wants to merge 2 commits into
Conversation
…it (red) With a decoy part first, the 2 MB cut falls inside the decoy and the `file` part never arrives. FastAPI then answers 422 "Field required", which tells the user their file is missing when the request was too big. Shubham noted this in his review of #470. Fails on main: 6 failed.
…d required" After UploadBodyLimit cuts a body, a 422 means the endpoint never ran: FastAPI found no whole `file` part in the shortened body. That answer is replaced with the same 400 the endpoints give for an oversized file, "The upload is larger than the 2 MB limit, so it was not read. Upload the file on its own." The endpoints' own refusals are left alone, and the response keeps its headers, so the session cookie still arrives.
ARSH871-bot
left a comment
There was a problem hiding this comment.
Reviewed fd8a3da, merged onto main cceffec. Approving.
Mutation. Your four, plus one more, each run against your test file and against main's copy:
mutant this PR main's copy
replace any status >= 400 9 failed 9 failed (the existing oversized/extension tests)
replace only when NOT cut 6 failed all pass
drop the app's headers (cookie) 6 failed all pass
keep the endpoint's body 6 failed all pass
no replacement at all 6 failed all pass
Nothing else moved. The same 21 boundary requests I used on #470 (each endpoint at 2 MB − 1, 2 MB, 2 MB + 1, + 1 KB, + 63 KB, + 70 KB, + 5 MB) give identical status and message on main and on this branch, so only the after-a-cut 422 changes.
CI-style suite on the merge: 2459 passed, 63 skipped (the 6 new cases over main). Ruff clean. I didn't re-run your real-uvicorn measurements; the table above is through main.app.
shubhamkataria2005
left a comment
There was a problem hiding this comment.
Approving at fd8a3da.
I sent uploads to /api/policy with a decoy part placed before file, so the cut lands where this PR is meant to handle it:
decoy size result
2,096,152 B 200, policy staged (the whole body fits, so nothing is cut)
2,197,152 B 400 "The upload is larger than the 2 MB limit, so it was not read. Upload the file on its own."
6 MB 400, same message
Cases that must not change:
- A small body with no
filepart is never cut, so it still gets FastAPI's 422 "Field required". - A single
filepart over the limit still gets the endpoint's own 400, which names the file.
The swapped response keeps its other headers. I checked that the netwise_session Set-Cookie from attach_session is still there and that content-length (103) matches the new body (103 bytes).
On the merged result: 2509 passed, 13 skipped, and ruff is clean.
Closes #479. Follows Shubham's note on #470 (review of Mon 16 Nov 13:56).
The change. After
UploadBodyLimitcuts a body, a 422 means the endpoint never ran: FastAPI found no wholefilepart in what it was shown. That answer is replaced with the 400 the endpoints already use for an oversized file, carrying this message:upload_config's docstring explains why).Before and after, through
main.app:mainUnchanged, compared case by case on all three endpoints. Status, message and cookie came out identical on
mainand on this branch:/api/ask(not limited, read in full)/api/uploadTests. Two commits, red first. The new test is parametrised over the three endpoints and two decoy sizes: 6 cases, each failing on
mainand passing here.test_upload_body_limit.pyCounts.
test_upload_body_limit.py: 45 passed.ruff check --select E4,E7,E9,Fis clean on both files.Not changed.
filepart is answered by the endpoint as before.Not checked. The frontend's display of the new message.
app.jsnever sends a second part, so it cannot produce this case.This is a follow-up to Shubham's note on #470 with no rush and is not needed for the week 7 deadline.