summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJacob Walls <jacobtylerwalls@gmail.com>2026-02-27 14:43:55 -0500
committerJacob Walls <jacobtylerwalls@gmail.com>2026-03-02 14:08:42 -0500
commit1b22d53bf67943cd193bbd6e327d955c19d2f5d2 (patch)
tree74b0eb2f02a0642d40426e2f841e80746219e43d
parent27ed90a8a829aa25f2ff3dc121f8429c2b06f662 (diff)
[6.0.x] Fixed #36961 -- Fixed TypeError in deprecation warnings if Django is imported by namespace.
Backport of c1d8646ec219b8b90ebdd463f40e5767876658a0 from main.
-rw-r--r--django/utils/deprecation.py5
-rw-r--r--docs/releases/6.0.3.txt3
-rw-r--r--tests/deprecation/tests.py4
3 files changed, 9 insertions, 3 deletions
diff --git a/django/utils/deprecation.py b/django/utils/deprecation.py
index eea24cf94b..11a37f05bc 100644
--- a/django/utils/deprecation.py
+++ b/django/utils/deprecation.py
@@ -12,9 +12,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: