Skip to content

Commit

Permalink
allowing ASGI to use drf_request in DjangoRequestExtractor (#3572)
Browse files Browse the repository at this point in the history
since we already have patched a request object (both ASGI/WSGI) before arriving, we should move patched-using logic closer to where it actually being used. for minimize impact and allow ASGI functionality.

---------

Co-authored-by: Ivana Kellyer <[email protected]>
  • Loading branch information
PakawiNz and sentrivana authored Oct 1, 2024
1 parent 4636afc commit 05411ff
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions sentry_sdk/integrations/django/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -491,13 +491,6 @@ def wsgi_request_event_processor(event, hint):
# We have a `asgi_request_event_processor` for this.
return event

try:
drf_request = request._sentry_drf_request_backref()
if drf_request is not None:
request = drf_request
except AttributeError:
pass

with capture_internal_exceptions():
DjangoRequestExtractor(request).extract_into_event(event)

Expand Down Expand Up @@ -530,6 +523,16 @@ def _got_request_exception(request=None, **kwargs):


class DjangoRequestExtractor(RequestExtractor):
def __init__(self, request):
# type: (Union[WSGIRequest, ASGIRequest]) -> None
try:
drf_request = request._sentry_drf_request_backref()
if drf_request is not None:
request = drf_request
except AttributeError:
pass
self.request = request

def env(self):
# type: () -> Dict[str, str]
return self.request.META
Expand Down

0 comments on commit 05411ff

Please sign in to comment.