Skip to content

Commit 5890920

Browse files
TimPansinolrafeeiumaannamalai
authored
Fix crash in route wrappers for Starlette 0.19.1 (#527)
* Fix crash in route wrappers for starlette 0.19.1 Co-authored-by: Lalleh Rafeei <[email protected]> Co-authored-by: Uma Annamalai <[email protected]> * [Mega-Linter] Apply linters fixes * Bump Tests Co-authored-by: Lalleh Rafeei <[email protected]> Co-authored-by: Uma Annamalai <[email protected]> Co-authored-by: TimPansino <[email protected]>
1 parent e152949 commit 5890920

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

newrelic/hooks/framework_starlette.py

+14-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,20 @@ def bind_add_exception_handler(exc_class_or_status_code, handler, *args, **kwarg
6161

6262
def wrap_route(wrapped, instance, args, kwargs):
6363
path, endpoint, args, kwargs = bind_endpoint(*args, **kwargs)
64-
endpoint = route_naming_wrapper(FunctionTraceWrapper(endpoint))
64+
endpoint = FunctionTraceWrapper(endpoint)
65+
66+
# Starlette name detection gets a bit confused with our wrappers
67+
# so the get_name function should be called and the result should
68+
# be cached on the wrapper.
69+
try:
70+
if not hasattr(endpoint, "__name__"):
71+
from starlette.routing import get_name
72+
73+
endpoint.__name__ = get_name(endpoint.__wrapped__)
74+
except Exception:
75+
pass
76+
77+
endpoint = route_naming_wrapper(endpoint)
6578
return wrapped(path, endpoint, *args, **kwargs)
6679

6780

0 commit comments

Comments
 (0)