From e87bee6f50d323a769d61e8f1ca685f45de24079 Mon Sep 17 00:00:00 2001 From: Aymeric Augustin Date: Sat, 15 Nov 2014 21:17:43 +0100 Subject: [PATCH] Used get_template_loaders in the cached loader. This ensures that enabling the cached loader doesn't change behavior. (Before this commit, it did when the list contained unusable loaders.) --- django/template/loaders/cached.py | 19 ++++--------------- django/template/loaders/utils.py | 8 ++++++-- 2 files changed, 10 insertions(+), 17 deletions(-) diff --git a/django/template/loaders/cached.py b/django/template/loaders/cached.py index 180ed9900d..cf9a62b831 100644 --- a/django/template/loaders/cached.py +++ b/django/template/loaders/cached.py @@ -6,10 +6,10 @@ to load templates from them in order, caching the result. import hashlib from django.template.base import TemplateDoesNotExist from django.template.loader import get_template_from_string, make_origin -from django.template.loaders.utils import find_template_loader from django.utils.encoding import force_bytes from .base import Loader as BaseLoader +from .utils import _get_template_loaders class Loader(BaseLoader): @@ -18,20 +18,9 @@ class Loader(BaseLoader): def __init__(self, loaders): self.template_cache = {} self.find_template_cache = {} - self._loaders = loaders - self._cached_loaders = [] - - @property - def loaders(self): - # Resolve loaders on demand to avoid circular imports - if not self._cached_loaders: - # Set self._cached_loaders atomically. Otherwise, another thread - # could see an incomplete list. See #17303. - cached_loaders = [] - for loader in self._loaders: - cached_loaders.append(find_template_loader(loader)) - self._cached_loaders = cached_loaders - return self._cached_loaders + # Use the private, non-caching version of get_template_loaders + # in case loaders isn't hashable. + self.loaders = _get_template_loaders(loaders) def cache_key(self, template_name, template_dirs): if template_dirs: diff --git a/django/template/loaders/utils.py b/django/template/loaders/utils.py index 4850c9f1aa..fe7234ea1c 100644 --- a/django/template/loaders/utils.py +++ b/django/template/loaders/utils.py @@ -10,9 +10,13 @@ from django.utils.module_loading import import_string @lru_cache.lru_cache() def get_template_loaders(): + return _get_template_loaders(settings.TEMPLATE_LOADERS) + + +def _get_template_loaders(template_loaders=None): loaders = [] - for loader_name in settings.TEMPLATE_LOADERS: - loader = find_template_loader(loader_name) + for template_loader in template_loaders: + loader = find_template_loader(template_loader) if loader is not None: loaders.append(loader) # Immutable return value because it will be cached and shared by callers.