Skip to content

Commit

Permalink
[2.2.x] Fixed #30479 -- Fixed detecting changes in manage.py by autor…
Browse files Browse the repository at this point in the history
…eloader when using StatReloader.

Regression in c8720e7.

Backport of b2790f7 from master
  • Loading branch information
orf authored and felixxm committed May 28, 2019
1 parent 853586e commit 5bf2c87
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
10 changes: 9 additions & 1 deletion django/utils/autoreload.py
Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions docs/releases/2.2.2.txt
Expand Up @@ -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`).
4 changes: 4 additions & 0 deletions tests/utils_tests/test_autoreload.py
Expand Up @@ -130,6 +130,10 @@ def test_module_without_spec(self):
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):
Expand Down

0 comments on commit 5bf2c87

Please sign in to comment.