Skip to content

Non-strict json_params_matcher raises TypeError on nested object/scalar mismatch #814

Description

@liuyaohui666

Reproduction

from unittest.mock import Mock
from responses import matchers

matcher = matchers.json_params_matcher({"page": 1}, strict_match=False)
matcher(Mock(body='{"page": {"type": "json"}}'))

Current behavior

The matcher raises TypeError: argument of type 'int' is not a container or iterable.

_filter_dict_recursively recurses whenever the actual value is a dictionary, even if the expected value at the same key is a scalar.

Expected behavior

This is an ordinary mismatch, so the matcher should return (False, reason) instead of raising. Non-strict matching should still recurse when both values are dictionaries.

I have a small fix and regression test ready.

AI assistance disclosure

OpenAI Codex (GPT-5) assisted with investigation, the reproducer, regression test, implementation, and drafting this report. I reviewed the changes and ran the relevant tests locally.

Metadata

Metadata

Assignees

No one assigned

    Projects

    Status
    Waiting for: Product Owner

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions