#30674: Autoreload fails to restart runserver when exception is
django.core.exceptions.ImproperlyConfigured
-------------------------------------+-------------------------------------
               Reporter:  Peter J.   |          Owner:  nobody
  Farrell                            |
                   Type:  Bug        |         Status:  new
              Component:  Utilities  |        Version:  2.2
               Severity:  Normal     |       Keywords:  autoreload watchman
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Django: 2.2.3 using pywatchman with Watchman in a Docker container.

 We are seeing this when there is a code syntax error in serializers for
 Django REST Framework. This causes the runserver to never reload even if
 the syntax error has been fixed and the file saved. The only way to
 resolve this is to restart the web container.

 {{{
 web_1      | Exception in thread django-main-thread:
 web_1      | Traceback (most recent call last):
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/urls/resolvers.py", line 581, in url_patterns
 web_1      |     iter(patterns)
 web_1      | TypeError: 'module' object is not iterable
 web_1      |
 web_1      | During handling of the above exception, another exception
 occurred:
 web_1      |
 web_1      | Traceback (most recent call last):
 web_1      |   File "/usr/lib/python3.5/threading.py", line 914, in
 _bootstrap_inner
 web_1      |     self.run()
 web_1      |   File "/usr/lib/python3.5/threading.py", line 862, in run
 web_1      |     self._target(*self._args, **self._kwargs)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/utils/autoreload.py", line 54, in wrapper
 web_1      |     fn(*args, **kwargs)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/commands/runserver.py", line 117, in
 inner_run
 web_1      |     self.check(display_num_errors=True)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/base.py", line 390, in check
 web_1      |     include_deployment_checks=include_deployment_checks,
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/base.py", line 377, in _run_checks
 web_1      |     return checks.run_checks(**kwargs)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/checks/registry.py", line 72, in run_checks
 web_1      |     new_errors = check(app_configs=app_configs)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/checks/urls.py", line 40, in
 check_url_namespaces_unique
 web_1      |     all_namespaces = _load_all_namespaces(resolver)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
 web_1      |     url_patterns = getattr(resolver, 'url_patterns', [])
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/utils/functional.py", line 80, in __get__
 web_1      |     res = instance.__dict__[self.name] = self.func(instance)
 web_1      |   File "/usr/local/lib/python3.5/dist-
 packages/django/urls/resolvers.py", line 588, in url_patterns
 web_1      |     raise
 ImproperlyConfigured(msg.format(name=self.urlconf_name))
 web_1      | django.core.exceptions.ImproperlyConfigured: The included
 URLconf 'XXXX.urls' does not appear to have any patterns in it. If you see
 valid patterns in the file then the issue is probably caused by a circular
 import.
 web_1      |
 }}}

  Whereas the same syntax in our Celery process outputs the right
 exception. When the syntax error is fixed -- the process restarts (we are
 using the autoreload process wrapped around our celery command in a custom
 management command for development):

 {{{
 celery_1   | Traceback (most recent call last):
 celery_1   |   File "manage.py", line 10, in <module>
 celery_1   |     execute_from_command_line(sys.argv)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/__init__.py", line 381, in
 execute_from_command_line
 celery_1   |     utility.execute()
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/__init__.py", line 375, in execute
 celery_1   |     self.fetch_command(subcommand).run_from_argv(self.argv)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/base.py", line 323, in run_from_argv
 celery_1   |     self.execute(*args, **cmd_options)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/base.py", line 361, in execute
 celery_1   |     self.check()
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/base.py", line 390, in check
 celery_1   |     include_deployment_checks=include_deployment_checks,
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/management/base.py", line 377, in _run_checks
 celery_1   |     return checks.run_checks(**kwargs)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/checks/registry.py", line 72, in run_checks
 celery_1   |     new_errors = check(app_configs=app_configs)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/checks/urls.py", line 40, in
 check_url_namespaces_unique
 celery_1   |     all_namespaces = _load_all_namespaces(resolver)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/core/checks/urls.py", line 57, in _load_all_namespaces
 celery_1   |     url_patterns = getattr(resolver, 'url_patterns', [])
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/utils/functional.py", line 80, in __get__
 celery_1   |     res = instance.__dict__[self.name] = self.func(instance)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/urls/resolvers.py", line 579, in url_patterns
 celery_1   |     patterns = getattr(self.urlconf_module, "urlpatterns",
 self.urlconf_module)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/utils/functional.py", line 80, in __get__
 celery_1   |     res = instance.__dict__[self.name] = self.func(instance)
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/urls/resolvers.py", line 572, in urlconf_module
 celery_1   |     return import_module(self.urlconf_name)
 celery_1   |   File "/usr/lib/python3.5/importlib/__init__.py", line 126,
 in import_module
 celery_1   |     return _bootstrap._gcd_import(name[level:], package,
 level)
 celery_1   |   File "<frozen importlib._bootstrap>", line 986, in
 _gcd_import
 celery_1   |   File "<frozen importlib._bootstrap>", line 969, in
 _find_and_load
 celery_1   |   File "<frozen importlib._bootstrap>", line 958, in
 _find_and_load_unlocked
 celery_1   |   File "<frozen importlib._bootstrap>", line 673, in
 _load_unlocked
 celery_1   |   File "<frozen importlib._bootstrap_external>", line 665, in
 exec_module
 celery_1   |   File "<frozen importlib._bootstrap>", line 222, in
 _call_with_frames_removed
 celery_1   |   File "/code/XXXXX/urls.py", line 22, in <module>
 celery_1   |     path('', include('api.urls', namespace='api')),
 celery_1   |   File "/usr/local/lib/python3.5/dist-
 packages/django/urls/conf.py", line 34, in include
 celery_1   |     urlconf_module = import_module(urlconf_module)
 celery_1   |   File "/usr/lib/python3.5/importlib/__init__.py", line 126,
 in import_module
 celery_1   |     return _bootstrap._gcd_import(name[level:], package,
 level)
 celery_1   |   File "<frozen importlib._bootstrap>", line 986, in
 _gcd_import
 celery_1   |   File "<frozen importlib._bootstrap>", line 969, in
 _find_and_load
 celery_1   |   File "<frozen importlib._bootstrap>", line 958, in
 _find_and_load_unlocked
 celery_1   |   File "<frozen importlib._bootstrap>", line 673, in
 _load_unlocked
 celery_1   |   File "<frozen importlib._bootstrap_external>", line 665, in
 exec_module
 celery_1   |   File "<frozen importlib._bootstrap>", line 222, in
 _call_with_frames_removed
 celery_1   |   File "/code/api/urls.py", line 5, in <module>
 celery_1   |     from .versioned.v1.router import api_urlpatterns as
 api_v1
 celery_1   |   File "/code/api/versioned/v1/router.py", line 3, in
 <module>
 celery_1   |     from .viewsets import YYYSet, XXXViewSet
 celery_1   |   File "/code/api/versioned/v1/viewsets.py", line 1, in
 <module>
 celery_1   |     from ...base.viewsets import *
 celery_1   |   File "/code/api/base/viewsets.py", line 3, in <module>
 celery_1   |     from .serializers import YYYSerializer,
 XXXReportSerializer
 celery_1   |   File "/code/api/base/serializers.py", line 201
 celery_1   |     'url',,,,
 celery_1   |           ^
 celery_1   | SyntaxError: invalid syntax
 }}}

-- 
Ticket URL: <https://code.djangoproject.com/ticket/30674>
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 django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/055.9ebccfa2bb7c4a4ca814969683fb3ab8%40djangoproject.com.

Reply via email to