Coerce a single value to a list when serializing list variables - #611
Merged
leszekhanusz merged 2 commits intoJul 24, 2026
Merged
Conversation
serialize_value assumed a value for a list type was already a list and
iterated it, so a string variable was split into its characters --
{'ids': 'abc'} was serialized as ['a', 'b', 'c'] and silently sent to
the server -- and a non-iterable such as an int raised TypeError.
The GraphQL spec's input coercion says a non-list value provided for a
list type is coerced to a list of one, which is what graphql-core does
in coerce_input_value. Use pyutils.is_iterable (already the module the
file imports inspect from) to match that behaviour; it also excludes
str and bytes, which is the case that was silently wrong.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #611 +/- ##
==========================================
Coverage 100.00% 100.00%
==========================================
Files 38 40 +2
Lines 2908 3329 +421
==========================================
+ Hits 2908 3329 +421 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
leszekhanusz
approved these changes
Jul 24, 2026
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.
Summary
serialize_valueassumes the value given for a list type is already a list and iterates it:So a single value passed for a list variable is taken apart instead of being wrapped. A string is split into its characters and sent to the server without any error:
The string case is the worrying one — no exception, just wrong data on the wire.
Fix
The GraphQL spec's input coercion says a non-list value provided for a list type is coerced to a list of one, and
graphql-coreimplements exactly that incoerce_input_value:This mirrors it using the same
graphql.pyutils.is_iterablehelper — the module this file already importsinspectfrom.is_iterablealso excludesstrandbytes, which is precisely the silently-wrong case above.After the change:
{"ids": "abc"} -> {'ids': ['abc']} {"ns": 5} -> {'ns': [5]} {"ids": ["a", "b"]} -> {'ids': ['a', 'b']} # unchanged {"ids": None} -> {'ids': None} # unchangedTests
Added
test_serialize_variables_single_value_for_list_typeintests/test_graphql_request.py, which fails before this change and passes after.pytest tests/test_graphql_request.py tests/custom_scalars/→ 57 passed. The 2 failures incustom_scalars/test_money.py(sync_transport) also fail on a clean checkout here — they need transport deps I don't have locally, and are unrelated to this change.black,flake8andisortare clean.