Repository navigation
Fix json_params_matcher never matching falsy JSON primitives (0, False, "") - #851
Open
tony1233200 wants to merge 1 commit into
Open
tony1233200 wants to merge 1 commit into
tony1233200 wants to merge 1 commit into
Conversation
json_params_matcher used (params or {}) for non-list params, so a
falsy top-level JSON primitive (0, False, "", 0.0) was silently
replaced with an empty dict and could never match a request body
containing that same primitive. Default to {} only when params is
None, which preserves the previous behavior for dicts, lists and
None while letting falsy scalars compare against the parsed body.
Fixes getsentry#834
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.
Fixes #834
json_params_matchernormalized its argument with(params or {})for non-list params, so a falsy top-level JSON primitive —0,False,"",0.0— was silently replaced by an empty dict and could never match a request whose body is that same primitive:The matcher now defaults to
{}only whenparams is None:This is behavior-identical for dicts (including
{}), lists (including[]),None, and truthy scalars; only falsy scalars change, from never matching to comparing against the parsed body as intended.Tests: parametrized regression tests cover
0,False,""and0.0both by calling the matcher directly and end-to-end throughrequests.post(..., json=value), plus a mismatch case (0against a""body) that must still fail. The new tests fail on unmodified master and pass with this change; the rest of the suite is unchanged (268 passed;test_fail_matchers_erroralready fails on unmodified master in this environment).