Skip to content

Commit

Permalink
[fix] fastapi: init inner_exception properly
Browse files Browse the repository at this point in the history
It looks to me that if the app does not yield anything for the response
you might encour into an attribute error as the attribut won't be defined yet.

In general, the init method sounds like a better place for shared attributes.

Fixes OCA#487
  • Loading branch information
simahawk committed Jan 9, 2025
1 parent dbbfea0 commit bbfbf5d
Showing 1 changed file with 5 additions and 1 deletion.
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
# 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

0 comments on commit bbfbf5d

Please sign in to comment.