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

Fix exception suppression in asgi transport #2669

Merged
merged 11 commits into from
May 21, 2023

Conversation

Nnonexistent
Copy link
Contributor

Bug description:

If httpx client uses asgi transport with raise_app_exceptions=False and response is not complete, exception is still raised.

This is mostly come up in tests where you want to check how your application behave in error states. But currently it works only with non-streaming responses, which is quite limiting.

I propose simple fix for such non-complete responses to be able to comply with the raise_app_exceptions=False.

Test case included.

tests/test_asgi.py Outdated Show resolved Hide resolved
async with httpx.AsyncClient(app=raise_exc, transport=transport) as client:
response = await client.get("http://www.example.org/")

assert response.status_code == 500
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the behaviour of this test before the code change?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Test failed with RuntimeError being raised from raise_exc

tests/test_asgi.py Outdated Show resolved Hide resolved
Nnonexistent and others added 3 commits April 20, 2023 16:29
Copy link
Member

@tomchristie tomchristie left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems reasonable, yup.

@tomchristie
Copy link
Member

Okay, let's also add this to the CHANGELOG.
What's the best user-facing description we can add here?

Return 500 error response instead of exceptions when raise_app_exceptions=False is set on ASGITransport.

Perhaps?

CHANGELOG.md Outdated Show resolved Hide resolved
@tomchristie tomchristie merged commit a682f6f into encode:master May 21, 2023
@trim21 trim21 mentioned this pull request Aug 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants