diff options
| author | Mike Edmunds <medmunds@gmail.com> | 2026-04-25 12:57:15 -0700 |
|---|---|---|
| committer | nessita <124304+nessita@users.noreply.github.com> | 2026-04-27 21:58:06 -0300 |
| commit | 32a3b4aa695e76ced1b2829b178e630b9ac62dce (patch) | |
| tree | 5a1f44b8ca052a143a25fd7612f70ef42ccaa6c3 /django/conf/__init__.py | |
| parent | a49be25e6128a3272960ed4f6f6506d147596395 (diff) | |
Refs #35514 -- Added warn_about_external_use() deprecation utility.
Implemented a new `warn_about_external_use()` helper to conditionally
issue warnings depending on whether a deprecated feature is used from
within Django.
Fixed `LazySettings._show_deprecation_warning()` (Refs #26029) to work
correctly when called from anywhere in `LazySettings`. Previously, it
assumed a specific code path through `LazyObject.__getattribute__()` and
an `@property` getter on `LazySettings`.
Diffstat (limited to 'django/conf/__init__.py')
| -rw-r--r-- | django/conf/__init__.py | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/django/conf/__init__.py b/django/conf/__init__.py index 25f5ffa305..dd0a158dfb 100644 --- a/django/conf/__init__.py +++ b/django/conf/__init__.py @@ -9,14 +9,16 @@ for a list of all possible variables. import importlib import os import time -import traceback import warnings from pathlib import Path -import django from django.conf import global_settings from django.core.exceptions import ImproperlyConfigured -from django.utils.deprecation import RemovedInDjango70Warning, django_file_prefixes +from django.utils.deprecation import ( + RemovedInDjango70Warning, + django_file_prefixes, + warn_about_external_use, +) from django.utils.functional import LazyObject, empty ENVIRONMENT_VARIABLE = "DJANGO_SETTINGS_MODULE" @@ -146,13 +148,19 @@ class LazySettings(LazyObject): return self._wrapped is not empty def _show_deprecation_warning(self, message, category): - stack = traceback.extract_stack() - # Show a warning if the setting is used outside of Django. - # Stack index: -1 this line, -2 the property, -3 the - # LazyObject __getattribute__(), -4 the caller. - filename, _, _, _ = stack[-4] - if not filename.startswith(os.path.dirname(django.__file__)): - warnings.warn(message, category, stacklevel=2) + """Issue a warning when external code uses a deprecated setting. + + Allow Django's own code to use it without emitting the warning. This + function should only be called from within LazySettings methods. + """ + warn_about_external_use( + message, + category, + skip_name_prefixes=( + "django.conf.LazySettings", + "django.utils.functional.LazyObject", + ), + ) class Settings: |
