summaryrefslogtreecommitdiff
path: root/django/template/backends
diff options
context:
space:
mode:
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])