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

Call exception handlers even if response started #758

Closed
wants to merge 2 commits into from

Conversation

aviramha
Copy link
Contributor

This change allows background tasks exceptions to be caught by exception handlers.
The implication is that handlers are always called, but response is rendered by the handlers only if not rendered yet.
** THIS IS A DRAFT ** I will add tests and document changes after initial approval.

@aviramha
Copy link
Contributor Author

#739

@aviramha aviramha marked this pull request as ready for review December 18, 2019 15:45
@aviramha
Copy link
Contributor Author

Added tests, 100% coverage :)

@@ -58,11 +58,26 @@ def test_websockets_should_raise():


def test_handled_exc_after_response():
# A 406 HttpException is raised *after* the response has already been sent.
# The exception middleware should raise a RuntimeError.
with pytest.raises(RuntimeError):
Copy link
Member

Choose a reason for hiding this comment

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

I would change the test much more simply here. A handled exception after the response is rendered isn't a problem now, we should just expect a 200 status code. We don't particularly need to check for side-effects.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Wouldn't we want to make sure that the exception handler runs? In case the response is already rendered, we get the same result even if it's not called

@Kludex
Copy link
Sponsor Member

Kludex commented Jan 29, 2022

As stated on #739, this is not something we're looking for. Let's go for #761.

Thanks for the PR @aviramha ! Also, sorry for the waiting time.

@Kludex Kludex closed this Jan 29, 2022
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.

None yet

3 participants