Skip to content
Myr

Fix exception suppression in asgi transport (#2669)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Nik · committed by GitHub · parent f9abbbb · Browse files · 3 files+18 added−1 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+18 added−1 removed

  • tests:+10 added−0 removed
  • other:+8 added−1 removed

3 files+18 added−1 removed

modified:httpx/_transports/asgi.py+7 added-1 removed
159 unmodified lines
160161 try:162 await self.app(scope, receive, send)163 except Exception: # noqa: PIE-786164 if self.raise_app_exceptions or not response_complete.is_set():164 if self.raise_app_exceptions:165 raise166167 response_complete.set()168 if status_code is None:169 status_code = 500170 if response_headers is None:171 response_headers = {}172173 assert response_complete.is_set()174 assert status_code is not None175 assert response_headers is not None176
3 unmodified lines
modified:tests/test_asgi.py+10 added
1 unmodified line
23import pytest45import httpx6from httpx import ASGITransport789async def hello_world(scope, receive, send):10 status = 200
180 unmodified lines
191 response = await client.post("http://www.example.org/", content=b"example")192193 assert response.status_code == 200194 assert disconnect195196197@pytest.mark.anyio198async def test_asgi_exc_no_raise():199 transport = ASGITransport(app=raise_exc, raise_app_exceptions=False)200 async with httpx.AsyncClient(transport=transport) as client:201 response = await client.get("http://www.example.org/")202203 assert response.status_code == 500
modified:CHANGELOG.md+1 added
6 unmodified lines
7## Unreleased89### Fixed1011* Return `500` error response instead of exceptions when `raise_app_exceptions=False` is set on `ASGITransport`. (#2669)12* Ensure all WSGITransport environs have a SERVER_PROTOCOL. (#2708)1314## 0.24.1 (17th May, 2023)15
1009 unmodified lines