diff --git a/drf_spectacular/drainage.py b/drf_spectacular/drainage.py index 8116d386..50e4f93c 100644 --- a/drf_spectacular/drainage.py +++ b/drf_spectacular/drainage.py @@ -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)