Skip to content

Distinguish JSON booleans from numbers in request matching - #842

Open
galafis wants to merge 1 commit into
getsentry:masterfrom
galafis:fix-json-boolean-number-matching
Open

galafis wants to merge 1 commit into
getsentry:masterfrom
galafis:fix-json-boolean-number-matching

Conversation

@galafis

@galafis galafis commented Oct 24, 2026

Copy link
Copy Markdown

json_params_matcher currently accepts {"enabled": 1} when the expectation is {"enabled": true}, and likewise equates false with 0. Python's bool/int equality leaks into JSON object and array comparison, so an incorrect request can satisfy a mock.

Compare JSON values recursively, distinguishing booleans from numbers while preserving equality between numeric 1 and 1.0. This applies to strict and partial dictionary matches, nested objects, and arrays. Add 12 mismatch regressions plus five equality controls.

Validation on Python 3.12.14 / requests 2.34.2: regression before fix: 12 failed, 5 passed. After fix: all 81 matcher tests and all 278 tests in responses/tests pass (18 deprecation warnings). Black and Flake8 pass. Mypy reports the same three pre-existing errors in fragment_identifier_matcher/test_recorder on unchanged source; no new type errors. git diff --check passes.

@galafis
galafis requested a review from markstory as a code owner October 24, 2026 17:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant