fix: Add patch for Django issue #30479 - StatReloader doesn't track manage.py

Apply this patch to django/utils/autoreload.py to fix the regression where
changes to manage.py don't trigger autoreloader restart.

The fix adds special case handling for the __main__ module which has
__spec__ = None but still needs to be tracked for file changes.

Example usage:
  git apply django-autoreloader-30479.patch
This commit is contained in:
Claude 2026-03-16 12:07:18 +00:00
parent fa726e38d2
commit 90c0eda561

View file

@ -0,0 +1,17 @@
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -80,6 +80,11 @@ def iter_modules_and_files(modules, include_packages=False):
"""
Iterate over all modules and yield their filenames.
"""
for module in modules:
+ # Special case for __main__ module (e.g., manage.py)
+ # It has __spec__ = None but we still want to track it
+ if module.__name__ == '__main__':
+ if hasattr(module, '__file__') and module.__file__:
+ yield module.__file__
+ continue
+
spec = getattr(module, "__spec__", None)
if spec is None:
continue