[3.1.x] Fixed #32202 -- Fixed autoreloader argument generation for Windows with Python 3.7-.

Backport of ead37dfb58 from master
This commit is contained in:
Carlton Gibson 2020-11-19 12:07:15 +01:00 committed by Carlton Gibson
parent 4f7517b5e0
commit 012822c7f9
3 changed files with 15 additions and 7 deletions

View File

@ -221,11 +221,15 @@ def get_child_arguments():
exe_entrypoint = py_script.with_suffix('.exe')
if exe_entrypoint.exists():
# Should be executed directly, ignoring sys.executable.
return [exe_entrypoint, *sys.argv[1:]]
# TODO: Remove str() when dropping support for PY37.
# args parameter accepts path-like on Windows from Python 3.8.
return [str(exe_entrypoint), *sys.argv[1:]]
script_entrypoint = py_script.with_name('%s-script.py' % py_script.name)
if script_entrypoint.exists():
# Should be executed as usual.
return [*args, script_entrypoint, *sys.argv[1:]]
# TODO: Remove str() when dropping support for PY37.
# args parameter accepts path-like on Windows from Python 3.8.
return [*args, str(script_entrypoint), *sys.argv[1:]]
raise RuntimeError('Script %s does not exist.' % py_script)
else:
args += sys.argv

View File

@ -17,3 +17,7 @@ Bugfixes
* Fixed crash of key transforms for :class:`~django.db.models.JSONField` on
PostgreSQL when using on a ``Subquery()`` annotation (:ticket:`32182`).
* Fixed a regression in Django 3.1 that caused a crash of auto-reloader for
certain invocations of ``runserver`` on Windows with Python 3.7 and below
(:ticket:`32202`).

View File

@ -177,10 +177,10 @@ class TestChildArguments(SimpleTestCase):
self.addCleanup(tmpdir.cleanup)
exe_path = Path(tmpdir.name) / 'django-admin.exe'
exe_path.touch()
with mock.patch('sys.argv', [exe_path.with_suffix(''), 'runserver']):
with mock.patch('sys.argv', [str(exe_path.with_suffix('')), 'runserver']):
self.assertEqual(
autoreload.get_child_arguments(),
[exe_path, 'runserver']
[str(exe_path), 'runserver']
)
@mock.patch('sys.warnoptions', [])
@ -189,10 +189,10 @@ class TestChildArguments(SimpleTestCase):
self.addCleanup(tmpdir.cleanup)
script_path = Path(tmpdir.name) / 'django-admin-script.py'
script_path.touch()
with mock.patch('sys.argv', [script_path.with_name('django-admin'), 'runserver']):
with mock.patch('sys.argv', [str(script_path.with_name('django-admin')), 'runserver']):
self.assertEqual(
autoreload.get_child_arguments(),
[sys.executable, script_path, 'runserver']
[sys.executable, str(script_path), 'runserver']
)
@mock.patch('sys.argv', ['does-not-exist', 'runserver'])
@ -413,7 +413,7 @@ class RestartWithReloaderTests(SimpleTestCase):
with tempfile.TemporaryDirectory() as temp_dir:
script = Path(temp_dir) / 'manage.py'
script.touch()
argv = [script, 'runserver']
argv = [str(script), 'runserver']
mock_call = self.patch_autoreload(argv)
autoreload.restart_with_reloader()
self.assertEqual(mock_call.call_count, 1)