Fix file uploads failing with HTTP 422 on 307/308 redirects#11290
Fix file uploads failing with HTTP 422 on 307/308 redirects#11290Dreamsorcerer merged 14 commits intomasterfrom
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
…P 422 on 307/308 redirects (#11297) **This is a backport of PR #11290 as merged into master (16703bb).** --------- Co-authored-by: J. Nick Koston <[email protected]>
…P 422 on 307/308 redirects (#11296) **This is a backport of PR #11290 as merged into master (16703bb).** --------- Co-authored-by: J. Nick Koston <[email protected]>
|
Feel free to make a PR with the changes, otherwise bdraco will likely review them later in the day. |
… comments from PR #11290 (#11319) **This is a backport of PR #11301 as merged into master (815901f).** Co-authored-by: J. Nick Koston <[email protected]>
… comments from PR #11290 (#11318) **This is a backport of PR #11301 as merged into master (815901f).** Co-authored-by: J. Nick Koston <[email protected]>
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.datatodata = req._bodyto avoid payload recreationaiohttp/payload.py
sizeproperty 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.txt11270.bugfix.rstinto theCHANGES/folder