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

[16.0][fix] fastapi: init inner_exception properly #488

Merged
merged 1 commit into from
Jan 30, 2025
Merged
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
6 changes: 5 additions & 1 deletion fastapi/fastapi_dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@
class FastApiDispatcher(Dispatcher):
routing_type = "fastapi"

def __init__(self, request):
super().__init__(request)
# Store exception to later raise it in the dispatch method if needed
self.inner_exception = None

@classmethod
def is_compatible_with(cls, request):
return True
Expand Down Expand Up @@ -47,7 +52,6 @@ def handle_error(self, exc):
def _make_response(self, status_mapping, headers_tuple, content):
self.status = status_mapping[:3]
self.headers = dict(headers_tuple)
self.inner_exception = None
Copy link
Contributor

Choose a reason for hiding this comment

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

IMO you still need to reset the inner_exception each time you process a new response

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@lmignon my understanding, but correct me if I'm wrong, is that the dispatcher will be re-initialized for each request. Now, if the assumption of the re-init per request is correct I wouldn't bother handling this differently.

Another point: even assuming you are correct, if you reset it for each iteration you might lose a previous exception. Hence, we should probably do a check if it is valued already and do not override it.

WDYT?

Copy link
Contributor

Choose a reason for hiding this comment

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

@simahawk I think I was wrong 😏

# in case of exception, the method asgi_done_callback of the
# ASGIResponder will trigger an "a2wsgi.error" event with the exception
# instance stored in a tuple with the type of the exception and the traceback.
Expand Down
Loading