Keep every URL value of a multipart list field - #5676
Open
AbdullahRasheed45 wants to merge 1 commit into
Open
Conversation
_build_multipart walks the values of a file field and splits them: real uploads are appended to the files list, while values the file manager returns as plain strings, such as HTTP URLs, went into data[name]. The string branch assigned rather than accumulated, so each value overwrote the previous one and a list field carrying several URLs arrived at the service with only the last. Real uploads were unaffected because that branch already appended. Collect the string values in a list instead. The aiohttp client also needs its FormData loop to add one field per value, since it feeds data entries to add_field one at a time. Both clients were affected and are fixed together.
AbdullahRasheed45
requested review from
jianshen92
and removed request for
a team
July 27, 2026 00:48
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #5675
The problem
_build_multipartwalks the values of a file field and splits them two ways: real uploads are appended to thefileslist, while values the file manager hands back as plain strings — HTTP URLs are passed through untouched — go intodata.The string branch assigned instead of accumulating:
So a
list[Path]field carrying several URLs reached the service with only the last one. Real uploads were never affected, because that branch already appended — which is why the issue's local-file control passed while the URL case lost values.Confirmed against the encoded request body on
main, with two URLs going in:The change
Collect the string values in a list so each is sent as its own part.
The aiohttp client (
proxy2) needed a second change: it feedsdataentries toFormData.add_fieldone at a time, which takes a single value, so the loop now adds one field per value. Without that it would have passed a list straight toadd_field.Both clients carried the same bug, so both are fixed here rather than in separate PRs.
Nothing changes for a field carrying a single value: one entry in, one part out, as before.
Tests
Added
tests/unit/_internal/client/test_multipart_list_fields.py, driving_build_multipartdirectly with a passthrough file manager so no network or running service is involved:mainpytest tests/unit/_internal/client/→ 6 passed for the new file.test_session_manager.py::test_session_refresh_creates_new_connectorfails in my environment, but it fails identically on an unmodified checkout (missing async plugin), so it is unrelated.ruff checkandruff formatare clean on all three files.ruff checkreports 9 pre-existing errors in the two client modules on an unmodified checkout as well; I left those alone to keep the diff to the bug.