mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #32783 -- Fixed crash of autoreloader when __main__ module doesn't have __spec__ attribute.
Regression in ec6d2531c5
.
Thanks JonathanNickelson for the report.
This commit is contained in:
parent
1143f3bb5e
commit
12b19a1d76
@ -222,7 +222,8 @@ def get_child_arguments():
|
|||||||
args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions]
|
args = [sys.executable] + ['-W%s' % o for o in sys.warnoptions]
|
||||||
# __spec__ is set when the server was started with the `-m` option,
|
# __spec__ is set when the server was started with the `-m` option,
|
||||||
# see https://docs.python.org/3/reference/import.html#main-spec
|
# see https://docs.python.org/3/reference/import.html#main-spec
|
||||||
if __main__.__spec__ is not None and __main__.__spec__.parent:
|
# __spec__ may not exist, e.g. when running in a Conda env.
|
||||||
|
if getattr(__main__, '__spec__', None) is not None and __main__.__spec__.parent:
|
||||||
args += ['-m', __main__.__spec__.parent]
|
args += ['-m', __main__.__spec__.parent]
|
||||||
args += sys.argv[1:]
|
args += sys.argv[1:]
|
||||||
elif not py_script.exists():
|
elif not py_script.exists():
|
||||||
|
@ -25,3 +25,6 @@ Bugfixes
|
|||||||
|
|
||||||
* Fixed a bug in Django 3.2 that would trigger the auto-reloader for template
|
* Fixed a bug in Django 3.2 that would trigger the auto-reloader for template
|
||||||
changes when directory paths were specified with strings (:ticket:`32744`).
|
changes when directory paths were specified with strings (:ticket:`32744`).
|
||||||
|
|
||||||
|
* Fixed a regression in Django 3.2 that caused a crash of auto-reloader with
|
||||||
|
``AttributeError``, e.g. inside a ``Conda`` environment (:ticket:`32783`).
|
||||||
|
@ -219,6 +219,17 @@ class TestChildArguments(SimpleTestCase):
|
|||||||
with self.assertRaisesMessage(RuntimeError, msg):
|
with self.assertRaisesMessage(RuntimeError, msg):
|
||||||
autoreload.get_child_arguments()
|
autoreload.get_child_arguments()
|
||||||
|
|
||||||
|
@mock.patch('sys.argv', [__file__, 'runserver'])
|
||||||
|
@mock.patch('sys.warnoptions', [])
|
||||||
|
def test_module_no_spec(self):
|
||||||
|
module = types.ModuleType('test_module')
|
||||||
|
del module.__spec__
|
||||||
|
with mock.patch.dict(sys.modules, {'__main__': module}):
|
||||||
|
self.assertEqual(
|
||||||
|
autoreload.get_child_arguments(),
|
||||||
|
[sys.executable, __file__, 'runserver']
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class TestUtilities(SimpleTestCase):
|
class TestUtilities(SimpleTestCase):
|
||||||
def test_is_django_module(self):
|
def test_is_django_module(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user