Skip to content

Commit 03709a5

Browse files
author
Voronov Vladimir
committed
fix(middleware): fix get api source
1 parent 25125e0 commit 03709a5

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

fastapi_structlog/middleware/utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,11 @@ def find_api_source(
7575
_: Optional[dict[str, Any]] = None,
7676
) -> Optional[dict[str, Any]]:
7777
"""Find location of endpoint."""
78-
if 'endpoint' in scope:
78+
if 'endpoint' in scope and hasattr(scope['endpoint'], '__globals__'):
7979
return {
80-
'package': scope['endpoint'].__globals__['__package__'],
81-
'file': scope['endpoint'].__globals__['__file__'],
82-
'function': scope['endpoint'].__name__,
80+
'package': scope['endpoint'].__globals__.get('__package__'),
81+
'file': scope['endpoint'].__globals__.get('__file__'),
82+
'function': getattr(scope['endpoint'], '__name__', None),
8383
}
8484
return None
8585

0 commit comments

Comments
 (0)