#30500: Error reporting returns a circular import error on a python formatting
error, and does not restart the development server
-------------------------------------+-------------------------------------
Reporter: Runner15 | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: error reporting, | Triage Stage:
error, circular import | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tom Forbes):
* status: closed => new
* cc: Tom Forbes (added)
* version: 2.2 => master
* resolution: invalid =>
Comment:
I've spent some time digging into this, and it is indeed a race condition
of some kind. I think it comes down to this CPython issue:
https://bugs.python.org/issue36284 (importlib.import_module() not thread
safe if Exception is raised (3.4, 3.5)). I've re-opened the ticket and
marked it against master, because it's not clear when or even if this is
fixed in Python core.
Basically, as far as I can tell, the code inside the autoreloader that
prevents one race condition causes another. Here it's racing the
'run_checks' method called from runserver's 'inner_run', which both load
the urlconf_module via the 'urlconf_module' cached property. In the case
of an error being thrown _and a race happening_, then the module returned
is not initialized correctly and has no 'urlpatterns' attribute. This
causes the "patterns = getattr(self.urlconf_module, "urlpatterns",
self.urlconf_module)" statement to fall back to the default, which is the
module object itself. This then fails the iteration.
The obvious thing to do here is to add a lock around 'urlconf_module', or
in the ticket linked above you can call `importlib.reload()` on the
result. I'd have a preference for the lock approach on all Python
versions, and after adding one I've not seen any failures after running
the reproduction script for half an hour.
--
Ticket URL: <https://code.djangoproject.com/ticket/30500#comment:14>
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 view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/066.59c5c9fc8c329af19f0e46018bb7f693%40djangoproject.com.