Skip to content

Commit 88e6716

Browse files
feat(django): Use functools.wraps in more places (#4144)
We're not using `@functools.wraps` in a handful of places in the Django integration, leading to the wrapped functions reporting wrong (i.e., Sentry wrapper) names when inspected. Closes #4138 --------- Co-authored-by: Daniel Szoke <[email protected]>
1 parent 889aec4 commit 88e6716

File tree

4 files changed

+8
-0
lines changed

4 files changed

+8
-0
lines changed

sentry_sdk/integrations/django/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import functools
12
import inspect
23
import sys
34
import threading
@@ -321,6 +322,7 @@ def _patch_drf():
321322
else:
322323
old_drf_initial = APIView.initial
323324

325+
@functools.wraps(old_drf_initial)
324326
def sentry_patched_drf_initial(self, request, *args, **kwargs):
325327
# type: (APIView, Any, *Any, **Any) -> Any
326328
with capture_internal_exceptions():
@@ -471,6 +473,7 @@ def _patch_get_response():
471473

472474
old_get_response = BaseHandler.get_response
473475

476+
@functools.wraps(old_get_response)
474477
def sentry_patched_get_response(self, request):
475478
# type: (Any, WSGIRequest) -> Union[HttpResponse, BaseException]
476479
_before_get_response(request)

sentry_sdk/integrations/django/asgi.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def patch_django_asgi_handler_impl(cls):
8888

8989
old_app = cls.__call__
9090

91+
@functools.wraps(old_app)
9192
async def sentry_patched_asgi_handler(self, scope, receive, send):
9293
# type: (Any, Any, Any, Any) -> Any
9394
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)
@@ -125,6 +126,7 @@ def patch_get_response_async(cls, _before_get_response):
125126
# type: (Any, Any) -> None
126127
old_get_response_async = cls.get_response_async
127128

129+
@functools.wraps(old_get_response_async)
128130
async def sentry_patched_get_response_async(self, request):
129131
# type: (Any, Any) -> Union[HttpResponse, BaseException]
130132
_before_get_response(request)
@@ -142,6 +144,7 @@ def patch_channels_asgi_handler_impl(cls):
142144
if channels.__version__ < "3.0.0":
143145
old_app = cls.__call__
144146

147+
@functools.wraps(old_app)
145148
async def sentry_patched_asgi_handler(self, receive, send):
146149
# type: (Any, Any, Any) -> Any
147150
integration = sentry_sdk.get_client().get_integration(DjangoIntegration)

sentry_sdk/integrations/django/signals_handlers.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ def patch_signals():
5050

5151
old_live_receivers = Signal._live_receivers
5252

53+
@wraps(old_live_receivers)
5354
def _sentry_live_receivers(self, sender):
5455
# type: (Signal, Any) -> Union[tuple[list[Callable[..., Any]], list[Callable[..., Any]]], list[Callable[..., Any]]]
5556
if DJANGO_VERSION >= (5, 0):

sentry_sdk/integrations/django/views.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ def patch_views():
3131
old_make_view_atomic = BaseHandler.make_view_atomic
3232
old_render = SimpleTemplateResponse.render
3333

34+
@functools.wraps(old_render)
3435
def sentry_patched_render(self):
3536
# type: (SimpleTemplateResponse) -> Any
3637
with sentry_sdk.start_span(

0 commit comments

Comments
 (0)