Fix json_params_matcher raising TypeError on nested vs scalar mismatch (#814) - #817
Closed
philsong4-ai wants to merge 1 commit into
Closed
Conversation
getsentry#814) _filtered_dict_recursively recursed whenever the value in the first dict was a mapping, without checking that the corresponding value in the second dict was also a mapping. When the actual JSON had a nested object but the expected params had a scalar at the same key (e.g. expected {"page": 1}, actual {"page": {"type": "json"}}), the recursive call did `key in <scalar>`, raising `TypeError: argument of type 'int' is not iterable`. Now we only recurse when BOTH values are mappings, so a type mismatch is reported as a normal non-match (False, reason) instead of crashing. Fixes getsentry#814.
markstory
reviewed
Sep 2, 2026
markstory
left a comment
Member
There was a problem hiding this comment.
Could you update the CHANGES file as well? You'll need to add a new section for 0.26.4
markstory
approved these changes
Sep 2, 2026
Member
|
Duplicate of #815 |
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
Fixes #814.
json_params_matcherwithstrict_match=FalseraisedTypeError: argument of type 'int' is not iterable(instead of reporting a normal mismatch) when the expected params had a scalar at a key but the actual JSON body had a nested object at the same key (and vice versa).Root cause
responses/matchers.py::_filter_dict_recursivelyrecursed whenever the value in the first dict was a mapping, without checking that the corresponding value in the second dict was also a mapping. The recursive call then didkey in <scalar>, which raised.Fix
Recurse only when both values are mappings:
A type mismatch at a key is now reported as a normal non-match
(False, reason)instead of crashing.Test
test_json_params_matcher_not_strict_scalar_vs_nested_does_not_raiseinresponses/tests/test_matchers.py, asserting the matcher returns(False, ...)(not raises) in both the scalar-vs-nested and nested-vs-scalar directions.