10000 [5.0.x] Fixed #35187 -- Fixed @sensitive_variables/sensitive_post_par… · django/django@41a4bba · GitHub
[go: up one dir, main page]

Skip to content

Commit 41a4bba

Browse files
committed
[5.0.x] Fixed #35187 -- Fixed @sensitive_variables/sensitive_post_parameters decorators crash with .pyc-only builds.
Thanks Jon Janzen for the implementation idea. Thanks Marcus Hoffmann for the report. Regression in 38e391e. Backport of d1be05b from main
1 parent 3a54e64 commit 41a4bba

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

django/views/decorators/debug.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,15 +47,17 @@ def decorator(func):
4747

4848
try:
4949
file_path = inspect.getfile(wrapped_func)
50-
_, first_file_line = inspect.getsourcelines(wrapped_func)
5150
except TypeError: # Raises for builtins or native functions.
5251
raise ValueError(
5352
f"{func.__name__} cannot safely be wrapped by "
5453
"@sensitive_variables, make it either non-async or defined in a "
5554
"Python file (not a builtin or from a native extension)."
5655
)
5756
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}")
5961

6062
if variables:
6163
coroutine_functions_to_sensitive_variables[key] = variables

docs/releases/5.0.3.txt

Lines changed: 4 a 644E dditions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,7 @@ Bugfixes
2020
would prevent filtering against foreign keys using lookups like ``__isnull``
2121
when the field was not included in :attr:`.ModelAdmin.list_filter`
2222
(: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`).

0 commit comments

Comments
 (0)
0