#32202 closed Bug (fixed)
django-admin runserver and get_child_arguments() crashes on Windows and Python < 3.8.
Reported by: | andrey-zotov | Owned by: | Carlton Gibson |
---|---|---|---|
Component: | Core (Management commands) | Version: | 3.1 |
Severity: | Release blocker | Keywords: | |
Cc: | Carlton Gibson, Tom Forbes | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
"django-admin runserver" fails with the following error:
Traceback (most recent call last): File "c:\users\someone\appdata\local\programs\python\python37\lib\runpy.py", line 193, in _run_module_as_main "__main__", mod_spec) File "c:\users\someone\appdata\local\programs\python\python37\lib\runpy.py", line 85, in _run_code exec(code, run_globals) File "C:\Users\someone\AppData\Local\Programs\Python\Python37\Scripts\django-admin.exe\__main__.py", line 7, in <module> File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\__init__.py", line 395, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv self.execute(*args, **cmd_options) File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\commands\runserver.py", line 61, in execute super().execute(*args, **options) File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\base.py", line 371, in execute output = self.handle(*args, **options) File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\commands\runserver.py", line 96, in handle self.run(**options) File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\core\management\commands\runserver.py", line 103, in run autoreload.run_with_reloader(self.inner_run, **options) File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\utils\autoreload.py", line 616, in run_with_reloader exit_code = restart_with_reloader() File "c:\users\someone\appdata\local\programs\python\python37\lib\site-packages\django\utils\autoreload.py", line 244, in restart_with_reloader p = subprocess.run(args, env=new_environ, close_fds=False) File "c:\users\someone\appdata\local\programs\python\python37\lib\subprocess.py", line 488, in run with Popen(*popenargs, **kwargs) as process: File "c:\users\someone\appdata\local\programs\python\python37\lib\subprocess.py", line 800, in __init__ restore_signals, start_new_session) File "c:\users\someone\appdata\local\programs\python\python37\lib\subprocess.py", line 1148, in _execute_child args = list2cmdline(args) File "c:\users\someone\appdata\local\programs\python\python37\lib\subprocess.py", line 555, in list2cmdline needquote = (" " in arg) or ("\t" in arg) or not arg TypeError: argument of type 'WindowsPath' is not iterable
Environment:
Windows 10
Python: 3.7.6
Django: 3.1.3
Steps to reproduce:
django-admin startproject mysite set PYTHONPATH=<thelocaldir> django-admin runserver --settings=mysite.settings
Apparently django.utils.autoreload.get_child_arguments returns WindowsPath("C:\Users\someone\AppData\Local\Programs\Python\Python37\Scripts\django-admin.exe") as the first argument,
and subprocess.Popen expects a string and is not able to use Path.
The following monkey-patch fixes the error:
def get_child_arguments_override(): args = autoreload._get_child_arguments() for i, arg in enumerate(args): if isinstance(arg, Path): args[i] = str(arg) return args autoreload._get_child_arguments = autoreload.get_child_arguments autoreload.get_child_arguments = get_child_arguments_override
Change History (6)
comment:1 by , 4 years ago
Cc: | added |
---|---|
Severity: | Normal → Release blocker |
Summary: | django-admin runserver and get_child_arguments → django-admin runserver and get_child_arguments() crashes on Windows and Python < 3.8. |
Triage Stage: | Unreviewed → Accepted |
comment:2 by , 4 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 4 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Note:
See TracTickets
for help on using tickets.
Tentatively accepted, I cannot check this on Windows, but it looks like a regression in 8a902b7ee622ada258d15fb122092c1f02b82698.
subprocess.run()
'sargs
parameter accepts path-like objects on Windows since Python 3.8 (see similar issue fordbshell
, #31076).