summaryrefslogtreecommitdiff
path: root/django/template/backends
diff options
context:
space:
mode:
authorAlex Hill <alex@hill.net.au>2016-03-09 11:35:39 +0800
committerTim Graham <timograham@gmail.com>2016-03-16 12:37:57 -0400
commitecb59cc6579402b68ddfd4499bf30edacf5963be (patch)
tree05c9af211caaf5a0de6576f2c9fb77f1d898a3cb /django/template/backends
parent460dab0b40cc072873893feb5dd6820fa0ee9e9d (diff)
Fixed #26306 -- Fixed memory leak in cached template loader.
Diffstat (limited to 'django/template/backends')
-rw-r--r--django/template/backends/django.py17
1 files changed, 14 insertions, 3 deletions
diff --git a/django/template/backends/django.py b/django/template/backends/django.py
index cc795aae1c..afe1a7cd23 100644
--- a/django/template/backends/django.py
+++ b/django/template/backends/django.py
@@ -68,13 +68,24 @@ class Template(object):
reraise(exc, self.backend)
-def reraise(exc, backend):
+def copy_exception(exc, backend=None):
"""
- Reraise TemplateDoesNotExist while maintaining template debug information.
+ Create a new TemplateDoesNotExist. Preserve its declared attributes and
+ template debug data but discard __traceback__, __context__, and __cause__
+ to make this object suitable for keeping around (in a cache, for example).
"""
- new = exc.__class__(*exc.args, tried=exc.tried, backend=backend)
+ backend = backend or exc.backend
+ new = exc.__class__(*exc.args, tried=exc.tried, backend=backend, chain=exc.chain)
if hasattr(exc, 'template_debug'):
new.template_debug = exc.template_debug
+ return new
+
+
+def reraise(exc, backend):
+ """
+ Reraise TemplateDoesNotExist while maintaining template debug information.
+ """
+ new = copy_exception(exc, backend)
six.reraise(exc.__class__, new, sys.exc_info()[2])