File tree Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Expand file tree Collapse file tree 2 files changed +8
-2
lines changed Original file line number Diff line number Diff line change @@ -47,15 +47,17 @@ def decorator(func):
47
47
48
48
try :
49
49
file_path = inspect .getfile (wrapped_func )
50
- _ , first_file_line = inspect .getsourcelines (wrapped_func )
51
50
except TypeError : # Raises for builtins or native functions.
52
51
raise ValueError (
53
52
f"{ func .__name__ } cannot safely be wrapped by "
54
53
"@sensitive_variables, make it either non-async or defined in a "
55
54
"Python file (not a builtin or from a native extension)."
56
55
)
57
56
else :
58
- key = hash (f"{ file_path } :{ first_file_line } " )
57
+ # A source file may not be available (e.g. in .pyc-only builds),
58
+ # use the first line number instead.
59
+ first_line_number = wrapped_func .__code__ .co_firstlineno
60
+ key = hash (f"{ file_path } :{ first_line_number } " )
59
61
60
62
if variables :
61
63
coroutine_functions_to_sensitive_variables [key ] = variables
Original file line number Diff line number Diff line change @@ -20,3 +20,7 @@ Bugfixes
20
20
would prevent filtering against foreign keys using lookups like ``__isnull``
21
21
when the field was not included in :attr:`.ModelAdmin.list_filter`
22
22
(:ticket:`35173`).
23
+
24
+ * Fixed a regression in Django 5.0 that caused a crash of
25
+ ``@sensitive_variables`` and ``@sensitive_post_parameters`` decorators on
26
+ functions loaded from ``.pyc`` files (:ticket:`35187`).
You can’t perform that action at this time.
0 commit comments