mirror of
https://github.com/django/django.git
synced 2024-12-28 12:06:22 +00:00
[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 in38e391e95f
. Backport ofd1be05b3e9
from main
This commit is contained in:
parent
3a54e64ef7
commit
41a4bba817
@ -47,7 +47,6 @@ def sensitive_variables(*variables):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
file_path = inspect.getfile(wrapped_func)
|
file_path = inspect.getfile(wrapped_func)
|
||||||
_, first_file_line = inspect.getsourcelines(wrapped_func)
|
|
||||||
except TypeError: # Raises for builtins or native functions.
|
except TypeError: # Raises for builtins or native functions.
|
||||||
raise ValueError(
|
raise ValueError(
|
||||||
f"{func.__name__} cannot safely be wrapped by "
|
f"{func.__name__} cannot safely be wrapped by "
|
||||||
@ -55,7 +54,10 @@ def sensitive_variables(*variables):
|
|||||||
"Python file (not a builtin or from a native extension)."
|
"Python file (not a builtin or from a native extension)."
|
||||||
)
|
)
|
||||||
else:
|
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:
|
if variables:
|
||||||
coroutine_functions_to_sensitive_variables[key] = variables
|
coroutine_functions_to_sensitive_variables[key] = variables
|
||||||
|
@ -20,3 +20,7 @@ Bugfixes
|
|||||||
would prevent filtering against foreign keys using lookups like ``__isnull``
|
would prevent filtering against foreign keys using lookups like ``__isnull``
|
||||||
when the field was not included in :attr:`.ModelAdmin.list_filter`
|
when the field was not included in :attr:`.ModelAdmin.list_filter`
|
||||||
(:ticket:`35173`).
|
(: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`).
|
||||||
|
Loading…
Reference in New Issue
Block a user