Skip to content

docs: clarify json_params_matcher non-strict matching and accepted types - #837

Open
mayureshsonawane17 wants to merge 1 commit into
getsentry:masterfrom
mayureshsonawane17:docs/clarify-json-params-matcher
Open

mayureshsonawane17 wants to merge 1 commit into
getsentry:masterfrom
mayureshsonawane17:docs/clarify-json-params-matcher

Conversation

@mayureshsonawane17

Copy link
Copy Markdown

Summary

This PR improves the documentation for in by:

  1. Clarifying that accepts JSON dictionaries, lists, and scalar values.
  2. Adding an explicit code example demonstrating partial matching with .

Test Plan

  • Verified RST syntax and rendered documentation.

Comment thread README.rst
"""""""""""""""""

Matching JSON encoded data can be done with ``matchers.json_params_matcher()``.
It supports JSON dictionaries, lists, and scalar values.

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The documentation for json_params_matcher() claims support for all scalar values, but the implementation incorrectly handles falsy scalars (0, False, ""), treating them as an empty dictionary {}.
Severity: MEDIUM

Suggested Fix

The implementation of json_params_matcher() should be updated to correctly handle falsy scalar values. Instead of relying on a truthiness check like param or {}, explicitly check if the parameter is None to decide whether to default to an empty dictionary. This will ensure that falsy values like 0, False, and "" are preserved and used for matching as documented.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.

Location: README.rst#L311

Potential issue: The documentation added at `README.rst:311` states that
`matchers.json_params_matcher()` supports scalar values. However, the implementation
uses a truthiness check that causes falsy scalar values like `0`, `False`, or `""` to be
coerced into an empty dictionary `{}`. Consequently, a user attempting to match a
request body containing a falsy scalar (e.g., `json_params_matcher(0)` for a body of
`"0"`) will experience a silent match failure, as the code will compare the parsed body
(`0`) against an empty dictionary (`{}`). This behavior contradicts the documentation.

Did we get this right? 👍 / 👎 to inform future reviews.

@mayureshsonawane17

Copy link
Copy Markdown
Author

Thank you for the review feedback! That is an accurate catch.

The underlying issue where falsy scalar JSON primitives (0, False, "", 0.0) are replaced with {} by (params or {}) in responses/matchers.py line 138 has been isolated and tracked in issue #834, with a dedicated fix and unit tests submitted in PR #836 (fix: preserve falsy scalar JSON primitives in json_params_matcher).

I have synchronized the documentation wording in this PR to align with the accepted parameter types while PR #836 resolves the implementation behavior.

@markstory

Copy link
Copy Markdown
Member

There is a lint error introduced by these changes, could we get that addressed?

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.

2 participants