From 5bf2c87ece216b00a55a6ec0d6c824c9edabf188 Mon Sep 17 00:00:00 2001 From: Tom Forbes Date: Mon, 27 May 2019 20:14:49 +0100 Subject: [2.2.x] Fixed #30479 -- Fixed detecting changes in manage.py by autoreloader when using StatReloader. Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca. Backport of b2790f74d4f38c8b297b7c1cef6875d2378f6fa6 from master --- django/utils/autoreload.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'django') 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 -- cgit v1.3