Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error Message for failed matches sorts arrays even if not originally sorted #704

Closed
IanMoran opened this issue Feb 1, 2024 · 0 comments · Fixed by #711
Closed

Error Message for failed matches sorts arrays even if not originally sorted #704

IanMoran opened this issue Feb 1, 2024 · 0 comments · Fixed by #711
Labels

Comments

@IanMoran
Copy link

IanMoran commented Feb 1, 2024

Describe the bug

When reporting a failure to match an incoming request with registered responses, arrays in a JSON body appear to be sorted even if they aren't sorted in reality, potentially masking the mismatch that caused the error.

Additional context

No response

Version of responses

0.24.1

Steps to Reproduce

import responses
import requests

json_match = {'array' : ['C', 'B', 'A']}

responses.post(url='http://example.com', 
body='{"example":"response"}',
match=[matchers.json_params_matcher(json_match)])

json_actual = {'array' : ['B', 'A', 'C']}
requests.post('http://example.com', json=json_actual)

Expected Result

Responses should throw an error with a message displaying the actual body compared to the registered mock, making the difference between the ordering of the two arrays clear.

Actual Result

Responses' error message appears, but displays both arrays as ['A', 'B', 'C'], making it seem like it should have been a match despite not being accurate to either array's actual state.

NOTE: This auto-sorting also occurs if the arrays DO match, but some other aspect of the json fails the comparison.

@markstory markstory added the bug label Feb 5, 2024
mgaligniana added a commit to mgaligniana/responses that referenced this issue Apr 26, 2024
mgaligniana added a commit to mgaligniana/responses that referenced this issue Apr 26, 2024
mgaligniana added a commit to mgaligniana/responses that referenced this issue Apr 30, 2024
Delete `_create_key_val_str` which was introduced for the compatibility
between python2 (not supported anymore) and python3.

Fixes getsentryGH-704
mgaligniana added a commit to mgaligniana/responses that referenced this issue Apr 30, 2024
Delete `_create_key_val_str` which was introduced for the compatibility
between python2 (not supported anymore) and python3.

Fixes getsentryGH-704
mgaligniana added a commit to mgaligniana/responses that referenced this issue Apr 30, 2024
Delete `_create_key_val_str` which was introduced for the compatibility
between python2 (not supported anymore) and python3.

Fixes getsentryGH-704
mgaligniana added a commit to mgaligniana/responses that referenced this issue May 1, 2024
Delete `_create_key_val_str` which was introduced for the compatibility
between python2 (not supported anymore) and python3.

Fixes getsentryGH-704
markstory pushed a commit that referenced this issue May 8, 2024
…711)

Delete `_create_key_val_str` which was introduced for the compatibility
between python2 (not supported anymore) and python3.

Fixes GH-704
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

3 participants