[Django] #32783: Recent commit causes issues when running manage.py as a script in a conda env. Django 3.2.3

19 views
Skip to first unread message

Django

unread,
May 25, 2021, 12:34:08 PM5/25/21
to django-...@googlegroups.com
#32783: Recent commit causes issues when running manage.py as a script in a conda
env. Django 3.2.3
---------------------------------------------+------------------------
Reporter: JonathanNickelson | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
---------------------------------------------+------------------------
The changes in this commit
https://github.com/django/django/commit/ec6d2531c59466924b645f314ac33f54470d7ac3
to def get_child_arguments() of django/utils/autoreload.py cause a crash
when running manage.py as a script from a conda env. For example:

{{{miniconda3/envs/promotion_tool_38/bin/manage.py runserver
10.12.123.45:8183}}} no longer works and gives this stacktrace:
{{{
Traceback (most recent call last):
File "miniconda3/envs/promotion_tool_38/bin/manage.py", line 4, in
<module>
__import__('pkg_resources').run_script('promotion-tool==1.0.28',
'manage.py')
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/pkg_resources/__init__.py", line 651, in run_script
self.require(requires)[0].run_script(script_name, ns)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/pkg_resources/__init__.py", line 1448, in run_script
exec(code, namespace, namespace)
File
"/site/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/promotion_tool-1.0.28-py3.7.egg/EGG-
INFO/scripts/manage.py", line 21, in <module>
main()
File
"/site/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/promotion_tool-1.0.28-py3.7.egg/EGG-
INFO/scripts/manage.py", line 17, in main
execute_from_command_line(sys.argv)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/__init__.py", line 419, in
execute_from_command_line
utility.execute()
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/commands/runserver.py", line 61, in
execute
super().execute(*args, **options)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/commands/runserver.py", line 96, in
handle
self.run(**options)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/core/management/commands/runserver.py", line 103, in
run
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/utils/autoreload.py", line 639, in run_with_reloader
exit_code = restart_with_reloader()
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/utils/autoreload.py", line 256, in
restart_with_reloader
args = get_child_arguments()
File "/home/srv_jaxqa/miniconda3/envs/promotion_tool_38/lib/python3.8
/site-packages/django/utils/autoreload.py", line 225, in
get_child_arguments
if __main__.__spec__ is not None and __main__.__spec__.parent:
AttributeError: module '__main__' has no attribute '__spec__'
}}}
The work around for this is to explicitly call the actual manage.py inside
the EGG-INFO like this:
{{{
~/miniconda3/envs/promotion_tool_38/lib/python3.8/site-
packages/promotion_tool-1.0.28-py3.7.egg/EGG-INFO/scripts/manage.py
runserver 10.12.123.45:8183
}}}
After reverting the changes locally found in this method
"get_child_arguments" in django/utils/autoreload.py in the commit above,
the command {{{miniconda3/envs/promotion_tool_38/bin/manage.py runserver
10.12.123.45:8183}}} works again, or if inside the conda env then just
{{{manage.py runserver 10.12.123.45:8183}}} works.

--
Ticket URL: <https://code.djangoproject.com/ticket/32783>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 25, 2021, 2:34:05 PM5/25/21
to django-...@googlegroups.com
#32783: Recent commit causes issues when running manage.py as a script in a conda
env. Django 3.2.3
-----------------------------------+--------------------------------------

Reporter: JonathanNickelson | Owner: nobody
Type: Bug | Status: new
Component: Utilities | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):

* cc: William Schwartz (added)
* easy: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/32783#comment:1>

Django

unread,
May 26, 2021, 1:58:12 AM5/26/21
to django-...@googlegroups.com
#32783: Auoreloader crashes in a conda env.
-------------------------------------+-------------------------------------
Reporter: JonathanNickelson | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Core (Management | Version: 3.2
commands) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => assigned
* severity: Normal => Release blocker
* component: Utilities => Core (Management commands)
* owner: nobody => Mariusz Felisiak
* stage: Unreviewed => Accepted


Comment:

It looks like an issue in Python (see e.g.
[https://bugs.python.org/issue42949 bop-42949]), as far as I'm aware
`__main__` should always have `__spec__` attribute (sometimes set to
`None` but still). Nevertheless we can fix it.

Regression in ec6d2531c59466924b645f314ac33f54470d7ac3.

--
Ticket URL: <https://code.djangoproject.com/ticket/32783#comment:2>

Django

unread,
May 26, 2021, 3:03:12 AM5/26/21
to django-...@googlegroups.com
#32783: Auoreloader crashes in a conda env.
-------------------------------------+-------------------------------------
Reporter: JonathanNickelson | Owner: Mariusz
| Felisiak
Type: Bug | Status: assigned
Component: Core (Management | Version: 3.2
commands) |
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/14449 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/32783#comment:3>

Django

unread,
May 26, 2021, 5:20:09 AM5/26/21
to django-...@googlegroups.com
#32783: Auoreloader crashes in a conda env.
-------------------------------------+-------------------------------------
Reporter: JonathanNickelson | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed

Component: Core (Management | Version: 3.2
commands) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"12b19a1d76e1a6f80923c8358290d605dacd65d4" 12b19a1]:
{{{
#!CommitTicketReference repository=""
revision="12b19a1d76e1a6f80923c8358290d605dacd65d4"
Fixed #32783 -- Fixed crash of autoreloader when __main__ module doesn't
have __spec__ attribute.

Regression in ec6d2531c59466924b645f314ac33f54470d7ac3.

Thanks JonathanNickelson for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32783#comment:4>

Django

unread,
May 26, 2021, 5:20:34 AM5/26/21
to django-...@googlegroups.com
#32783: Auoreloader crashes in a conda env.
-------------------------------------+-------------------------------------
Reporter: JonathanNickelson | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Core (Management | Version: 3.2
commands) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"246a31a843dc7ea7b49d6a4491cb035776224194" 246a31a]:
{{{
#!CommitTicketReference repository=""
revision="246a31a843dc7ea7b49d6a4491cb035776224194"
[3.2.x] Fixed #32783 -- Fixed crash of autoreloader when __main__ module


doesn't have __spec__ attribute.

Regression in ec6d2531c59466924b645f314ac33f54470d7ac3.

Thanks JonathanNickelson for the report.

Backport of 12b19a1d76e1a6f80923c8358290d605dacd65d4 from main
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/32783#comment:5>

Django

unread,
Jun 2, 2021, 1:18:33 PM6/2/21
to django-...@googlegroups.com
#32783: Auoreloader crashes in a conda env.
-------------------------------------+-------------------------------------
Reporter: JonathanNickelson | Owner: Mariusz
| Felisiak
Type: Bug | Status: closed
Component: Core (Management | Version: 3.2
commands) |
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Daniel Hahler):

Just for reference: the crash also happened with `python -m pdb
./manage.py runserver`.

--
Ticket URL: <https://code.djangoproject.com/ticket/32783#comment:6>

Reply all
Reply to author
Forward
0 new messages