summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2019-05-27 20:14:49 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-05-28 09:01:29 +0200
commit5bf2c87ece216b00a55a6ec0d6c824c9edabf188 (patch)
treed1446e9a68f3542e8b9720148c4a3e2fcbd91f8b
parent853586ee2cb168fccb8ffc36c943cc97e2aed874 (diff)
[2.2.x] Fixed #30479 -- Fixed detecting changes in manage.py by autoreloader when using StatReloader.
Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca. Backport of b2790f74d4f38c8b297b7c1cef6875d2378f6fa6 from master
-rw-r--r--django/utils/autoreload.py10
-rw-r--r--docs/releases/2.2.2.txt3
-rw-r--r--tests/utils_tests/test_autoreload.py4
3 files changed, 16 insertions, 1 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index de889c99bb..ade9abdfdf 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -111,7 +111,15 @@ def iter_modules_and_files(modules, extra_files):
# During debugging (with PyDev) the 'typing.io' and 'typing.re' objects
# are added to sys.modules, however they are types not modules and so
# cause issues here.
- if not isinstance(module, ModuleType) or getattr(module, '__spec__', None) is None:
+ if not isinstance(module, ModuleType):
+ continue
+ if module.__name__ == '__main__':
+ # __main__ (usually manage.py) doesn't always have a __spec__ set.
+ # Handle this by falling back to using __file__, resolved below.
+ # See https://docs.python.org/reference/import.html#main-spec
+ sys_file_paths.append(module.__file__)
+ continue
+ if getattr(module, '__spec__', None) is None:
continue
spec = module.__spec__
# Modules could be loaded from places without a concrete location. If
diff --git a/docs/releases/2.2.2.txt b/docs/releases/2.2.2.txt
index d68338dce2..fc47100844 100644
--- a/docs/releases/2.2.2.txt
+++ b/docs/releases/2.2.2.txt
@@ -18,3 +18,6 @@ Bugfixes
* Fixed a regression in Django 2.2.1 where
:class:`~django.contrib.postgres.search.SearchVector` generates SQL with a
redundant ``Coalesce`` call (:ticket:`30488`).
+
+* Fixed a regression in Django 2.2 where auto-reloader doesn't detect changes
+ in ``manage.py`` file when using ``StatReloader`` (:ticket:`30479`).
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index f0e692d274..9253482e7b 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -130,6 +130,10 @@ class TestIterModulesAndFiles(SimpleTestCase):
del module.__spec__
self.assertEqual(autoreload.iter_modules_and_files((module,), frozenset()), frozenset())
+ def test_main_module_is_resolved(self):
+ main_module = sys.modules['__main__']
+ self.assertFileFound(Path(main_module.__file__))
+
class TestCommonRoots(SimpleTestCase):
def test_common_roots(self):