Commit cd46947d authored by Ivan Tsouvarev's avatar Ivan Tsouvarev Committed by Tim Graham
Browse files

[1.9.x] Fixed #26280 -- Fixed cached template loader crash when loading nonexistent template.

Backport of 8890c533 from master
parent 911a77fc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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
Original line number Diff line number Diff line
@@ -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.