[2.2.x] Fixed #30500 -- Fixed race condition in loading URLconf module.
This commit is contained in:
parent
6c17b86590
commit
6402855098
|
@ -381,6 +381,7 @@ class URLResolver:
|
||||||
self._callback_strs = set()
|
self._callback_strs = set()
|
||||||
self._populated = False
|
self._populated = False
|
||||||
self._local = threading.local()
|
self._local = threading.local()
|
||||||
|
self._urlconf_lock = threading.Lock()
|
||||||
|
|
||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
if isinstance(self.urlconf_name, list) and self.urlconf_name:
|
if isinstance(self.urlconf_name, list) and self.urlconf_name:
|
||||||
|
@ -568,10 +569,14 @@ class URLResolver:
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def urlconf_module(self):
|
def urlconf_module(self):
|
||||||
if isinstance(self.urlconf_name, str):
|
# import_module is not thread safe if the module throws an exception
|
||||||
return import_module(self.urlconf_name)
|
# during import, and can return an empty module object in Python < 3.6
|
||||||
else:
|
# (see https://bugs.python.org/issue36284).
|
||||||
return self.urlconf_name
|
with self._urlconf_lock:
|
||||||
|
if isinstance(self.urlconf_name, str):
|
||||||
|
return import_module(self.urlconf_name)
|
||||||
|
else:
|
||||||
|
return self.urlconf_name
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def url_patterns(self):
|
def url_patterns(self):
|
||||||
|
|
|
@ -22,3 +22,6 @@ Bugfixes
|
||||||
:attr:`ModelAdmin.list_filter <django.contrib.admin.ModelAdmin.list_filter>`
|
:attr:`ModelAdmin.list_filter <django.contrib.admin.ModelAdmin.list_filter>`
|
||||||
choices to foreign objects don't respect a model's ``Meta.ordering``
|
choices to foreign objects don't respect a model's ``Meta.ordering``
|
||||||
(:ticket:`30449`).
|
(:ticket:`30449`).
|
||||||
|
|
||||||
|
* Fixed a race condition in loading URLconf module that could cause a crash of
|
||||||
|
auto-reloader on Python 3.5 and below (:ticket:`30500`).
|
||||||
|
|
Loading…
Reference in New Issue