[Django] #30215: `AttributeError: __spec__` on `./manage.py runserver`

16 views
Skip to first unread message

Django

unread,
Feb 25, 2019, 9:55:29 PM2/25/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: flaviut | Owner: nobody
Type: Bug | Status: new
Component: Core | Version: 2.2
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 1
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
I get a `AttributeError: __spec__` when I try using the live server.
Here's the full stack trace:


{{{
$ pipenv run ./manage.py runserver
Watchman unavailable: pywatchman not installed.
Watching for file changes with StatReloader
Performing system checks…

Traceback (most recent call last):
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/py/_vendored_packages/apipkg.py", line 141, in __makeattr
modpath, attrname = self.__map__[name]
KeyError: '__spec__'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/home/user/dev/inventory/manage.py", line 15, in <module>
execute_from_command_line(sys.argv)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/__init__.py", line 381, in
execute_from_command_line
utility.execute()
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/commands/runserver.py", line 60, in
execute
super().execute(*args, **options)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 579, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 564, in start_django
reloader.run(django_main_thread)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 275, in run
self.run_loop()
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 281, in run_loop
next(ticker)
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 321, in tick
state.update(self.loop_files(state, previous_timestamp))
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 328, in loop_files
for path, mtime in self.snapshot_files():
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 348, in snapshot_files
for file in self.watched_files():
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 241, in watched_files
yield from iter_all_python_module_files()
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 103, in
iter_all_python_module_files
return iter_modules_and_files(modules, frozenset(_error_files))
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/django/utils/autoreload.py", line 114, in iter_modules_and_files
if not isinstance(module, ModuleType) or module.__spec__ is None:
File "/home/user/etc/.virtualenvs/inventory-HrJj1m_g/lib/python3.7/site-
packages/py/_vendored_packages/apipkg.py", line 146, in __makeattr
raise AttributeError(name)
AttributeError: __spec__
}}}


The fix is really simple: in {{{django/utils/autoreload.py}}}, line 114,
put {{{or not hasattr(module, '__spec__')}}} before {{{or module.__spec__
is None:}}}

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

Django

unread,
Feb 25, 2019, 9:56:12 PM2/25/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: flaviut | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 2.2
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0

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

Comment (by flaviut):

(fyi I'm on 2.2b1)

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

Django

unread,
Feb 25, 2019, 10:36:11 PM2/25/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: flaviut | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Simon Charette):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

As you've reported `getattr(module, '__spec__', None) is None` should do.

Are you interested in submitting a Github PR to address the issue?

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

Django

unread,
Feb 26, 2019, 3:17:14 AM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: flaviut | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by shiningfm):

Hello
Just for my information, I'm new to contributing (never submitted a patch
yet), and I'm trying to reproduce the bug, just to learn how it works, but
I can't.
I checked out the tag 2.2b1, installed requirements in a virtualenv,
started a new project, and fired ./manage runserver
What other steps can I take to reproduce the bug?
(sorry if this not the right place to discuss it)

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

Django

unread,
Feb 26, 2019, 3:54:16 AM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: nobody
Type: Bug | Status: new

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Florian Moussous):

* cc: Florian Moussous (added)


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

Django

unread,
Feb 26, 2019, 9:47:44 AM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: nobody
Type: Bug | Status: new

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Flaviu Tamas):

I should have done a better job presenting a reproducible case.

1. {{{pip install django==2.2b py}}}
2. {{{django-admin startproject mysite}}}
3. Add {{{import py}}} to the top of {{{mysite/mysite/urls.py}}}
4. {{{./manage.py runserver}}} and the error will show up.

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

Django

unread,
Feb 26, 2019, 1:18:29 PM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner:
| approdriguez
Type: Bug | Status: assigned

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by approdriguez):

* status: new => assigned
* owner: nobody => approdriguez


Comment:

Wops sorry, I did not see the comment, do you still want the issue or can
I do it? @Florian Moussous

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

Django

unread,
Feb 26, 2019, 1:22:37 PM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner:
| approdriguez
Type: Bug | Status: assigned
Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Florian Moussous):

Actually I was wondering if someone already posted a patch somewhere
because the checkbox "Has patch" is checked... So I did not send the PR
yet because I don't want to cause a mess ^^
But if the problem still needs fixing, I'd be glad to do so: I've already
written the patch and the test to go with it.

--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:7>

Django

unread,
Feb 26, 2019, 1:33:09 PM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: (none)
Type: Bug | Status: new

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by approdriguez):

* status: assigned => new
* owner: approdriguez => (none)


--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:8>

Django

unread,
Feb 26, 2019, 1:33:30 PM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: (none)
Type: Bug | Status: new

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by approdriguez):

Feel free then :)

--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:9>

Django

unread,
Feb 26, 2019, 1:36:27 PM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: Florian
| Moussous
Type: Bug | Status: assigned

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Florian Moussous):

* status: new => assigned

* owner: (none) => Florian Moussous


Comment:

Thanks ^^

--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:10>

Django

unread,
Feb 26, 2019, 2:06:35 PM2/26/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: Florian
| Moussous
Type: Bug | Status: assigned
Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Florian Moussous):

Work available here: https://github.com/shiningfm/django/tree/ticket_30215
PR submitted: https://github.com/django/django/pull/11029

--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:11>

Django

unread,
Feb 27, 2019, 10:36:18 AM2/27/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: Florian
| Moussous
Type: Bug | Status: closed

Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

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


Comment:

In [changeset:"4dac17ac93d0fa48ffb806a6cb142c54cc09e8f1" 4dac17ac]:
{{{
#!CommitTicketReference repository=""
revision="4dac17ac93d0fa48ffb806a6cb142c54cc09e8f1"
[2.2.x] Fixed #30215 -- Fixed autoreloader crash for modules without
__spec__.

Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca.
Backport of 99cfb28e995388db109e2f2ed15307f09945dda8 from master.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:12>

Django

unread,
Feb 27, 2019, 10:36:21 AM2/27/19
to django-...@googlegroups.com
#30215: `AttributeError: __spec__` on `./manage.py runserver`
-------------------------------------+-------------------------------------
Reporter: Flaviu Tamas | Owner: Florian
| Moussous
Type: Bug | Status: closed
Component: Core (Management | Version: 2.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: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"99cfb28e995388db109e2f2ed15307f09945dda8" 99cfb28]:
{{{
#!CommitTicketReference repository=""
revision="99cfb28e995388db109e2f2ed15307f09945dda8"


Fixed #30215 -- Fixed autoreloader crash for modules without __spec__.

Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/30215#comment:13>

Reply all
Reply to author
Forward
0 new messages