fix: query_param_matcher no longer mutates the caller's params dict#801
Merged
markstory merged 2 commits intoJun 26, 2026
Merged
Conversation
markstory
approved these changes
Jun 25, 2026
markstory
left a comment
Member
There was a problem hiding this comment.
Could you also add a note to the CHANGES file about this fix?
Contributor
Author
|
Added the CHANGES entry in Verification: I first tried the system |
Numeric values (int/float) in the params mapping were being converted to strings in-place, silently modifying the original dict passed by the caller. Copy the mapping into a local dict before performing the int/float→str normalisation.
gaoflow
force-pushed
the
fix/query-param-matcher-mutates-input
branch
from
June 26, 2026 11:13
03e670a to
e2f6b30
Compare
Contributor
Author
|
Rebased onto current Verification after the rebase: uv run --with pytest --with pytest-asyncio --with requests --with urllib3 --with pyyaml --with types-PyYAML python -m pytest responses/tests/test_matchers.py::test_query_param_matcher_does_not_mutate_input -q
git diff --check origin/master...HEAD |
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.
Problem
query_param_matcherconvertsintandfloatvalues to strings so they canbe compared against URL query-string values (which are always strings). However,
this conversion was done in-place on the dict reference obtained via
params_dict = params or {}, which aliases the original dict when a non-emptymapping is passed. As a result, every numeric value in the caller's dict is
silently overwritten with its string equivalent:
This is surprising behaviour that can cause hard-to-debug failures when the
same dict is inspected or reused after the matcher is created.
Fix
Copy the mapping into a fresh dict before the normalisation loop:
A regression test (
test_query_param_matcher_does_not_mutate_input) isincluded.
This pull request was prepared with the assistance of AI, under my direction and review.