Reputation: 10121
When running python manage.py runserver --settings=project.settings_dev
I get:
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/usr/local/lib/python3.7/site-packages/django/core/management/__init__.py", line 375, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 323, in run_from_argv
self.execute(*args, **cmd_options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 60, in execute
super().execute(*args, **options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/base.py", line 364, in execute
output = self.handle(*args, **options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 95, in handle
self.run(**options)
File "/usr/local/lib/python3.7/site-packages/django/core/management/commands/runserver.py", line 102, in run
autoreload.run_with_reloader(self.inner_run, **options)
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 600, in run_with_reloader
start_django(reloader, main_func, *args, **kwargs)
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 585, in start_django
reloader.run(django_main_thread)
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 303, in run
self.run_loop()
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 309, in run_loop
next(ticker)
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 349, in tick
for filepath, mtime in self.snapshot_files():
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 365, in snapshot_files
for file in self.watched_files():
File "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 264, in watched_files
yield from iter_all_python_module_files()
File "/usr/local/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 "/usr/local/lib/python3.7/site-packages/django/utils/autoreload.py", line 131, in iter_modules_and_files
if spec.has_location:
AttributeError: 'str' object has no attribute 'has_location'
This is the function that errors: https://github.com/django/django/blob/master/django/utils/autoreload.py#L131
@functools.lru_cache(maxsize=1)
def iter_modules_and_files(modules, extra_files):
"""Iterate through all modules needed to be watched."""
sys_file_paths = []
for module in modules:
# During debugging (with PyDev) the 'typing.io' and 'typing.re' objects
# are added to sys.modules, however they are types not modules and so
# cause issues here.
if not isinstance(module, ModuleType):
continue
if module.__name__ == '__main__':
# __main__ (usually manage.py) doesn't always have a __spec__ set.
# Handle this by falling back to using __file__, resolved below.
# See https://docs.python.org/reference/import.html#main-spec
# __file__ may not exists, e.g. when running ipdb debugger.
if hasattr(module, '__file__'):
sys_file_paths.append(module.__file__)
continue
if getattr(module, '__spec__', None) is None:
continue
spec = module.__spec__
# Modules could be loaded from places without a concrete location. If
# this is the case, skip them.
if type(spec) is str:
import ipdb; ipdb.set_trace()
if spec.has_location:
origin = spec.loader.archive if isinstance(spec.loader, zipimporter) else spec.origin
sys_file_paths.append(origin)
results = set()
for filename in itertools.chain(sys_file_paths, extra_files):
if not filename:
continue
path = pathlib.Path(filename)
try:
if not path.exists():
# The module could have been removed, don't fail loudly if this
# is the case.
continue
results.add(path.resolve().absolute())
except ValueError as e:
# Network filesystems may return null bytes in file paths.
logger.debug('"%s" raised when resolving path: "%s"' % (str(e), path))
return frozenset(results)
After placing an ipdb
debugger in django/utils/autoreload.py:131
the f if
type(spec) is str:
import ipdb; ipdb.set_trace()
and printing out __module__.__name__
and __module__.__file__
I get:
ipdb> module.__name__
'toml'
ipdb> module.__file__
'/usr/local/lib/python3.7/site-packages/toml.py'
ipdb>
Does anyone know what is the issue?
By replacing line :131
of django/utils/autoreload.py
to
if type(spec) is not str and spec.has_location:
Dev server is somehow running...
Upvotes: 1
Views: 740
Reputation: 10121
pip install toml==0.10.0
Updating toml to the latest version from PyPi worked https://pypi.org/project/toml/
Upvotes: 3
Reputation: 2321
I think this part is buggy:
if type(spec) is str:
import ipdb; ipdb.set_trace()
if spec.has_location:
origin = spec.loader.archive if isinstance(spec.loader, zipimporter) else spec.origin
sys_file_paths.append(origin)
elif
should be used instead of the second if
:
if type(spec) is str:
import ipdb; ipdb.set_trace()
elif spec.has_location:
origin = spec.loader.archive if isinstance(spec.loader, zipimporter) else spec.origin
sys_file_paths.append(origin)
Upvotes: 0