Răsfoiți Sursa

Fixed #26280 -- Fixed cached template loader crash when loading nonexistent template.

Ivan Tsouvarev 9 ani în urmă
părinte
comite
8890c533e0

+ 1 - 1
django/template/loaders/cached.py

@@ -131,7 +131,7 @@ class Loader(BaseLoader):
         template_tuple = self.template_cache.get(key)
         # A cached previous failure:
         if template_tuple is TemplateDoesNotExist:
-            raise TemplateDoesNotExist
+            raise TemplateDoesNotExist(template_name)
         elif template_tuple is None:
             template, origin = self.find_template(template_name, template_dirs)
             if not hasattr(template, 'render'):

+ 3 - 0
docs/releases/1.9.3.txt

@@ -46,3 +46,6 @@ Bugfixes
 * Changed the admin's "permission denied" message in the login template to use
   ``get_username`` instead of ``username`` to support custom user models
   (:ticket:`26231`).
+
+* Fixed a crash when passing a nonexistent template name to the cached template
+  loader's ``load_template()`` method (:ticket:`26280`).

+ 12 - 0
tests/template_tests/test_loaders.py

@@ -87,6 +87,18 @@ class CachedLoaderTests(SimpleTestCase):
             "Cached loader failed to cache the TemplateDoesNotExist exception",
         )
 
+    @ignore_warnings(category=RemovedInDjango20Warning)
+    def test_load_nonexistent_cached_template(self):
+        loader = self.engine.template_loaders[0]
+        template_name = 'nonexistent.html'
+
+        # fill the template cache
+        with self.assertRaises(TemplateDoesNotExist):
+            loader.find_template(template_name)
+
+        with self.assertRaisesMessage(TemplateDoesNotExist, template_name):
+            loader.get_template(template_name)
+
     def test_templatedir_caching(self):
         """
         #13573 -- Template directories should be part of the cache key.