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

[PR #8742/b4f9cb35 backport][3.11] Fix status not being set when ClientResponse.json raises ContentTypeError #8746

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES/8742.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed :meth:`aiohttp.ClientResponse.json()` not setting ``status`` when :exc:`aiohttp.ContentTypeError` is raised -- by :user:`bdraco`.
1 change: 1 addition & 0 deletions aiohttp/client_reqrep.py
Original file line number Diff line number Diff line change
Expand Up @@ -1199,6 +1199,7 @@ async def json(
raise ContentTypeError(
self.request_info,
self.history,
status=self.status,
message=(
"Attempt to decode JSON with " "unexpected mimetype: %s" % ctype
),
Expand Down
2 changes: 2 additions & 0 deletions tests/test_client_response.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,11 +659,13 @@ async def test_json_invalid_content_type(loop, session) -> None:
)
response._headers = {"Content-Type": "data/octet-stream"}
response._body = b""
response.status = 500

with pytest.raises(aiohttp.ContentTypeError) as info:
await response.json()

assert info.value.request_info == response.request_info
assert info.value.status == 500


async def test_json_no_content(loop, session) -> None:
Expand Down
Loading