mirror of
https://github.com/django/django.git
synced 2025-08-03 10:34:04 +00:00
Fixed #26306 -- Fixed memory leak in cached template loader.
This commit is contained in:
parent
460dab0b40
commit
ecb59cc657
4 changed files with 79 additions and 10 deletions
|
@ -49,11 +49,46 @@ class CachedLoaderTests(SimpleTestCase):
|
|||
self.assertEqual(template.origin.template_name, 'index.html')
|
||||
self.assertEqual(template.origin.loader, self.engine.template_loaders[0].loaders[0])
|
||||
|
||||
def test_get_template_missing(self):
|
||||
def test_get_template_missing_debug_off(self):
|
||||
"""
|
||||
With template debugging disabled, the raw TemplateDoesNotExist class
|
||||
should be cached when a template is missing. See ticket #26306 and
|
||||
docstrings in the cached loader for details.
|
||||
"""
|
||||
self.engine.debug = False
|
||||
with self.assertRaises(TemplateDoesNotExist):
|
||||
self.engine.get_template('doesnotexist.html')
|
||||
e = self.engine.template_loaders[0].get_template_cache['doesnotexist.html']
|
||||
self.assertEqual(e.args[0], 'doesnotexist.html')
|
||||
self.engine.get_template('prod-template-missing.html')
|
||||
e = self.engine.template_loaders[0].get_template_cache['prod-template-missing.html']
|
||||
self.assertEqual(e, TemplateDoesNotExist)
|
||||
|
||||
def test_get_template_missing_debug_on(self):
|
||||
"""
|
||||
With template debugging enabled, a TemplateDoesNotExist instance
|
||||
should be cached when a template is missing.
|
||||
"""
|
||||
self.engine.debug = True
|
||||
with self.assertRaises(TemplateDoesNotExist):
|
||||
self.engine.get_template('debug-template-missing.html')
|
||||
e = self.engine.template_loaders[0].get_template_cache['debug-template-missing.html']
|
||||
self.assertIsInstance(e, TemplateDoesNotExist)
|
||||
self.assertEqual(e.args[0], 'debug-template-missing.html')
|
||||
|
||||
@unittest.skipIf(six.PY2, "Python 2 doesn't set extra exception attributes")
|
||||
def test_cached_exception_no_traceback(self):
|
||||
"""
|
||||
When a TemplateDoesNotExist instance is cached, the cached instance
|
||||
should not contain the __traceback__, __context__, or __cause__
|
||||
attributes that Python sets when raising exceptions.
|
||||
"""
|
||||
self.engine.debug = True
|
||||
with self.assertRaises(TemplateDoesNotExist):
|
||||
self.engine.get_template('no-traceback-in-cache.html')
|
||||
e = self.engine.template_loaders[0].get_template_cache['no-traceback-in-cache.html']
|
||||
|
||||
error_msg = "Cached TemplateDoesNotExist must not have been thrown."
|
||||
self.assertIsNone(e.__traceback__, error_msg)
|
||||
self.assertIsNone(e.__context__, error_msg)
|
||||
self.assertIsNone(e.__cause__, error_msg)
|
||||
|
||||
@ignore_warnings(category=RemovedInDjango20Warning)
|
||||
def test_load_template(self):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue