summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2019-08-25 18:13:15 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-08-27 20:09:30 +0200
commit6402855098f773f15adc2139286a552ded84f3d7 (patch)
treeb55e582ab412addddeb782087f4a89b147ee8d3e /django
parent6c17b865905c203b21c1bcb6079261bd1cbf5e6a (diff)
[2.2.x] Fixed #30500 -- Fixed race condition in loading URLconf module.
Diffstat (limited to 'django')
-rw-r--r--django/urls/resolvers.py13
1 files changed, 9 insertions, 4 deletions
diff --git a/django/urls/resolvers.py b/django/urls/resolvers.py
index 9d3379a821..5b722474c9 100644
--- a/django/urls/resolvers.py
+++ b/django/urls/resolvers.py
@@ -381,6 +381,7 @@ class URLResolver:
self._callback_strs = set()
self._populated = False
self._local = threading.local()
+ self._urlconf_lock = threading.Lock()
def __repr__(self):
if isinstance(self.urlconf_name, list) and self.urlconf_name:
@@ -568,10 +569,14 @@ class URLResolver:
@cached_property
def urlconf_module(self):
- if isinstance(self.urlconf_name, str):
- return import_module(self.urlconf_name)
- else:
- return self.urlconf_name
+ # import_module is not thread safe if the module throws an exception
+ # during import, and can return an empty module object in Python < 3.6
+ # (see https://bugs.python.org/issue36284).
+ with self._urlconf_lock:
+ if isinstance(self.urlconf_name, str):
+ return import_module(self.urlconf_name)
+ else:
+ return self.urlconf_name
@cached_property
def url_patterns(self):