Code

Ticket #17303: 17303.diff

File 17303.diff, 1012 bytes (added by akaariai, 3 years ago)
Line 
1diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py
2index 3ed9cf3..702d6b6 100644
3--- a/django/template/loaders/cached.py
4+++ b/django/template/loaders/cached.py
5@@ -19,8 +19,14 @@ class Loader(BaseLoader):
6     def loaders(self):
7         # Resolve loaders on demand to avoid circular imports
8         if not self._cached_loaders:
9+            # Note that it is important to set the self._cached_loaders only
10+            # after all the self._loaders have been added to the list.
11+            # Otherwise concurrent access to this property could see
12+            # half-loaded _cached_loaders list. See #17303 for details.
13+            cached_loaders = []
14             for loader in self._loaders:
15-                self._cached_loaders.append(find_template_loader(loader))
16+                cached_loaders.append(find_template_loader(loader))
17+            self._cached_loaders = cached_loaders
18         return self._cached_loaders
19 
20     def find_template(self, name, dirs=None):