#30215 closed Bug (fixed)
`AttributeError: __spec__` on `./manage.py runserver`
| Reported by: | Flaviu Tamas | Owned by: | Florian Moussous |
|---|---|---|---|
| Component: | Core (Management commands) | Version: | 2.2 |
| Severity: | Release blocker | Keywords: | |
| Cc: | Florian Moussous | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | yes | UI/UX: | no |
Description
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:
Change History (13)
comment:1 by , 7 years ago
comment:2 by , 7 years ago
| Severity: | Normal → Release blocker |
|---|---|
| Triage Stage: | Unreviewed → Accepted |
As you've reported getattr(module, '__spec__', None) is None should do.
Are you interested in submitting a Github PR to address the issue?
comment:3 by , 7 years ago
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)
comment:4 by , 7 years ago
| Cc: | added |
|---|
comment:5 by , 7 years ago
I should have done a better job presenting a reproducible case.
pip install django==2.2b pydjango-admin startproject mysite- Add
import pyto the top ofmysite/mysite/urls.py ./manage.py runserverand the error will show up.
comment:6 by , 7 years ago
| Owner: | changed from to |
|---|---|
| Status: | new → assigned |
Wops sorry, I did not see the comment, do you still want the issue or can I do it? @Florian Moussous
comment:7 by , 7 years ago
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.
comment:8 by , 7 years ago
| Owner: | removed |
|---|---|
| Status: | assigned → new |
comment:11 by , 7 years ago
Work available here: https://github.com/shiningfm/django/tree/ticket_30215
PR submitted: https://github.com/django/django/pull/11029
(fyi I'm on 2.2b1)