Skip to content

Commit

Permalink
[PR #8742/b4f9cb35 backport][3.10] Fix status not being set when Clie…
Browse files Browse the repository at this point in the history
…ntResponse.json raises ContentTypeError (#8745)

Co-authored-by: J. Nick Koston <nick@koston.org>
fixes #8741
  • Loading branch information
patchback[bot] authored Aug 19, 2024
1 parent fbfedd6 commit c7ff47b
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 0 deletions.
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

0 comments on commit c7ff47b

Please sign in to comment.