-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Fix file uploads failing with HTTP 422 on 307/308 redirects #11290
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
✅ All tests successful. No failed tests found. Additional details and impacted files@@ Coverage Diff @@
## master #11290 +/- ##
========================================
Coverage 98.84% 98.84%
========================================
Files 131 131
Lines 43257 43433 +176
Branches 2326 2331 +5
========================================
+ Hits 42756 42933 +177
Misses 346 346
+ Partials 155 154 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
CodSpeed Performance ReportMerging #11290 will not alter performanceComparing Summary
|
Backport to 3.12: 💚 backport PR created✅ Backport PR branch: Backported as #11296 🤖 @patchback |
(cherry picked from commit 16703bb)
Backport to 3.13: 💚 backport PR created✅ Backport PR branch: Backported as #11297 🤖 @patchback |
(cherry picked from commit 16703bb)
@Dreamsorcerer, as you are getting to merge it to the version branches, can you check my comments above? They are not so significant, though. |
Feel free to make a PR with the changes, otherwise bdraco will likely review them later in the day. |
What do these changes do?
These changes fix a bug where file uploads fail with HTTP 422 errors when encountering 307/308 redirects. The issue occurs because:
The fix includes:
Are there changes in behavior for the user?
File uploads that encounter 307/308 redirects will now work correctly instead of failing with HTTP 422 errors. This is a bug fix that restores expected behavior - no breaking changes.
Is it a substantial burden for the maintainers to support this?
No. The changes are minimal and focused:
Related issue number
Fixes #11270
Implementation Details
Changes Made
aiohttp/client.py
data = req.data
todata = req._body
to avoid payload recreationaiohttp/payload.py
size
property to store start position on first accesstests/test_payload.py
tests/test_client_functional.py
Technical Explanation
The root cause identified by Cycloctane in the issue: "Two requests share the same BufferedReaderPayload instance, while the second request get zero Content-Length."
This happens because:
file_size - current_position
, which equals 0 at EOFThe fix stores the initial file position when size is first accessed, then always calculates size from that position. This ensures consistent Content-Length across multiple uses of the same payload instance.
Checklist
CONTRIBUTORS.txt
11270.bugfix.rst
into theCHANGES/
folder