Handle nested JSON type mismatches in non-strict matcher - #815
Open
liuyaohui666 wants to merge 1 commit into
Open
Handle nested JSON type mismatches in non-strict matcher#815liuyaohui666 wants to merge 1 commit into
liuyaohui666 wants to merge 1 commit into
Conversation
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.
What type of PR is this? (check all applicable)
Description
In non-strict mode,
json_params_matchercurrently raisesTypeErrorwhen the actual value at a matched key is a nested object but the expected value is a scalar._filter_dict_recursivelyassumes the expected value is also a dictionary before recursing.This change only recurses when both sides are dictionaries. The resulting filtered value then goes through the matcher's normal comparison path and produces a useful mismatch reason.
Related Tickets & Documents
Fixes #814
Added/updated tests?
The regression test covers an actual nested object compared with an expected scalar in non-strict mode.
Local verification:
pytest responses/tests/test_matchers.py -q— 43 passedpytest-httpserverwas unavailable in the local environment.git diff --checkUpdated CHANGES?
Are there any post deployment tasks we need to perform?
None.
AI assistance disclosure
OpenAI Codex (GPT-5) assisted with investigation, the reproducer, regression test, implementation, and drafting this PR. I reviewed the diff and ran the checks listed above locally.