Skip to content

Commit

Permalink
Fixed #35187 -- Fixed @sensitive_variables/sensitive_post_parameters …
Browse files Browse the repository at this point in the history
…decorators crash with .pyc-only builds.

Thanks Jon Janzen for the implementation idea.

Thanks Marcus Hoffmann for the report.

Regression in 38e391e.
  • Loading branch information
felixxm authored Feb 17, 2024
1 parent 7a05b8a commit d1be05b
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
6 changes: 4 additions & 2 deletions django/views/decorators/debug.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,17 @@ def decorator(func):

try:
file_path = inspect.getfile(wrapped_func)
_, first_file_line = inspect.getsourcelines(wrapped_func)
except TypeError: # Raises for builtins or native functions.
raise ValueError(
f"{func.__name__} cannot safely be wrapped by "
"@sensitive_variables, make it either non-async or defined in a "
"Python file (not a builtin or from a native extension)."
)
else:
key = hash(f"{file_path}:{first_file_line}")
# A source file may not be available (e.g. in .pyc-only builds),
# use the first line number instead.
first_line_number = wrapped_func.__code__.co_firstlineno
key = hash(f"{file_path}:{first_line_number}")

if variables:
coroutine_functions_to_sensitive_variables[key] = variables
Expand Down
4 changes: 4 additions & 0 deletions docs/releases/5.0.3.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,7 @@ Bugfixes
would prevent filtering against foreign keys using lookups like ``__isnull``
when the field was not included in :attr:`.ModelAdmin.list_filter`
(:ticket:`35173`).

* Fixed a regression in Django 5.0 that caused a crash of
``@sensitive_variables`` and ``@sensitive_post_parameters`` decorators on
functions loaded from ``.pyc`` files (:ticket:`35187`).

0 comments on commit d1be05b

Please sign in to comment.