Skip to content

Commit

Permalink
improve warning for transient @api_view objects #889
Browse files Browse the repository at this point in the history
source line is non-existent, however we do have a file to emit.
  • Loading branch information
tfranzel committed Dec 15, 2022
1 parent 46e63b9 commit cdeb4a4
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions drf_spectacular/drainage.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,16 +112,20 @@ def add_trace_message(obj):
def _get_source_location(obj):
try:
sourcefile = inspect.getsourcefile(obj)
except: # noqa: E722
sourcefile = None
try:
lineno = inspect.getsourcelines(obj)[1]
return sourcefile, lineno
except: # noqa: E722
return None, None
lineno = None
return sourcefile, lineno


def _get_current_trace():
source_locations = [t for t in _TRACES if t[0]]
if source_locations:
source_location = f"{source_locations[-1][0]}:{source_locations[-1][1]}"
sourcefile, lineno, _ = source_locations[-1]
source_location = f'{sourcefile}:{lineno}' if lineno else sourcefile
else:
source_location = ''
breadcrumbs = ' > '.join(t[2] for t in _TRACES)
Expand Down

0 comments on commit cdeb4a4

Please sign in to comment.