#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/050.31e282a32a73581915d6e0f1d07b5dc1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to