Skip to content

feat(matchers): add ignore_order option to json_params_matcher (#756) - #839

Open
mayureshsonawane17 wants to merge 1 commit into
getsentry:masterfrom
mayureshsonawane17:feat/756-json-params-ignore-order
Open

mayureshsonawane17 wants to merge 1 commit into
getsentry:masterfrom
mayureshsonawane17:feat/756-json-params-ignore-order

Conversation

@mayureshsonawane17

Copy link
Copy Markdown

Summary

Fixes #756.

This PR introduces an optional ignore_order: bool = False parameter to matchers.json_params_matcher(). When ignore_order=True, elements within JSON lists/arrays (both top-level and nested) are matched without regard to ordering, using recursive multiset equality.

Key Changes

  • Added _compare_json helper in responses/matchers.py supporting order-insensitive list comparison.
  • Added ignore_order: bool = False argument to json_params_matcher with full backwards compatibility.
  • Added unit tests in responses/tests/test_matchers.py for reordered lists, nested dictionary structures, duplicate elements, and length mismatches.
  • Updated README.rst with documentation and an example of ignore_order=True usage.

Test Plan

  • Ran pytest responses/tests/test_matchers.py (57 passed).
  • Ran full test suite pytest responses/tests/ (254 passed cleanly).

@cursor cursor Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 603ce1d. Configure here.

Comment thread responses/matchers.py
elif ignore_order:
valid = _compare_json(json_params, json_body, ignore_order=True)
else:
valid = json_params == json_body

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inverted empty-body matching condition

Medium Severity

Refactoring the match condition inverted the None check. json_params_matcher with params=None no longer accepts an empty JSON object body, and params={} now matches a missing request body. Both differ from the previous request_body is None short-circuit.

Fix in Cursor Fix in Web

Reviewed by Cursor Bugbot for commit 603ce1d. Configure here.

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.

Feature request: Flag to ignore ordering in matchers.json_param_matcher

1 participant