Repository navigation
Preserve scalar leaves in nested form data - #410
Draft
lexingtonhibiki wants to merge 1 commit into
Draft
lexingtonhibiki wants to merge 1 commit into
lexingtonhibiki wants to merge 1 commit into
Conversation
Keep non-iterable values for the standard URL encoder when a sibling requires nested expansion. Preserve existing iterable pair containers and propagate their errors instead of changing array conventions.
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.
Problem
formdata.urlencodeaccepts a scalar such aspage=1on its own, but adding a valid nested sibling makes the scalar fail during flattening:The expansion loop runs while any dict/list/tuple remains. Its helper then tries to unpack every non-string value, including non-iterable scalar leaves. This also occurs at deeper levels and with booleans,
None, and floats.Change
After the existing mapping-to-pairs conversion, leave values without either the iterator or sequence protocol for the standard-library encoder. Keep the existing strings/bytes path and expansion of mappings, generators, custom pair iterables, and legacy
__getitem__sequences. Exceptions fromitems(), iterator construction/consumption, and malformed pairs still propagate.This preserves the encoder's existing scalar conversion rather than introducing an array encoding convention. It does not address #350 or #367, change
doseq, or add dependencies.Validation
Python 3.12, local focused form-data module with socket, DNS and subprocess guards:
doseqvalues, and existing custom-container/error behavior.git diff --checkand Python syntax checks pass.The guarded runner preloads Betamax before replacing socket entry points, producing one pytest assertion-rewrite warning. The full-suite check below is separate from this focused run. Full tox, older Python versions, local Sphinx, and flake8 have not been validated here; hosted Actions remains approval-gated. No human review is claimed.
Full-suite follow-up
Ran the complete suite on Linux/Python 3.12.14 in fresh archives of this exact head (
d170830) and upstream base (bcd5f7b), using the same existing dependency environment and offline guard. No tests were deselected.DeprecationWarning-as-error: candidate 27 failed, 259 passed, 5 skipped; base 27 failed, 139 passed, 5 skipped. The 27 failing test IDs match exactly and fail on pre-existing Betamax/pyOpenSSL deprecations.datetime.datetime.utcnow(),Passing pyOpenSSL X509 objects is deprecated, andPassing pyOpenSSL PKey objects is deprecated): candidate 286 passed, 5 skipped; base 166 passed, 5 skipped.This establishes no additional full-suite failures in this environment, not a strict-warning or supported-version matrix pass. Dependencies include requests 2.32.3, urllib3 2.8.0, Betamax 0.9.0 and pyOpenSSL 25.3.0.
Prepared and independently reviewed with AI assistance.