diff options
| author | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-02-27 14:43:55 -0500 |
|---|---|---|
| committer | Jacob Walls <jacobtylerwalls@gmail.com> | 2026-03-02 14:08:11 -0500 |
| commit | c1d8646ec219b8b90ebdd463f40e5767876658a0 (patch) | |
| tree | 03e1fa655a4c78330f886d5d09c140db343b8037 | |
| parent | 3f21cb06e76044ad753055700395e54a1fc4f1e9 (diff) | |
Fixed #36961 -- Fixed TypeError in deprecation warnings if Django is imported by namespace.
| -rw-r--r-- | django/utils/deprecation.py | 5 | ||||
| -rw-r--r-- | docs/releases/6.0.3.txt | 3 | ||||
| -rw-r--r-- | tests/deprecation/tests.py | 4 |
3 files changed, 9 insertions, 3 deletions
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py index daa485eb35..4aa1183216 100644 --- a/django/utils/deprecation.py +++ b/django/utils/deprecation.py @@ -13,9 +13,8 @@ from django.utils.inspect import signature @functools.cache def django_file_prefixes(): - try: - file = django.__file__ - except AttributeError: + file = getattr(django, "__file__", None) + if file is None: return () return (os.path.dirname(file),) diff --git a/docs/releases/6.0.3.txt b/docs/releases/6.0.3.txt index 048921db8b..8777b1ef21 100644 --- a/docs/releases/6.0.3.txt +++ b/docs/releases/6.0.3.txt @@ -17,6 +17,9 @@ Bugfixes to :ref:`override<tuple-for-params>` ``as_sql()`` to accept any sequence (:ticket:`36934`). +* Fixed :exc:`TypeError` when deprecation warnings are emitted in environments + importing Django by namespace (:ticket:`36961`). + * Fixed a visual regression where fieldset legends were misaligned in the admin (:ticket:`36920`). diff --git a/tests/deprecation/tests.py b/tests/deprecation/tests.py index 2df9cc6fa2..ac610b4928 100644 --- a/tests/deprecation/tests.py +++ b/tests/deprecation/tests.py @@ -18,6 +18,10 @@ class DjangoFilePrefixesTests(SimpleTestCase): def test_no_file(self): orig_file = django.__file__ try: + # Depending on the cwd, Python might give a local checkout + # precedence over installed Django, producing None. + django.__file__ = None + self.assertEqual(django_file_prefixes(), ()) del django.__file__ self.assertEqual(django_file_prefixes(), ()) finally: |
