Code

Ticket #11461: template-dont-wrap-exception.diff

File template-dont-wrap-exception.diff, 2.2 KB (added by Glenn, 5 years ago)
Line 
1Index: django/template/debug.py
2===================================================================
3--- django/template/debug.py    (revision 10645)
4+++ django/template/debug.py    (working copy)
5@@ -69,16 +69,10 @@
6     def render_node(self, node, context):
7         try:
8             result = node.render(context)
9-        except TemplateSyntaxError, e:
10+        except Exception, e:
11             if not hasattr(e, 'source'):
12                 e.source = node.source
13             raise
14-        except Exception, e:
15-            from sys import exc_info
16-            wrapped = TemplateSyntaxError(u'Caught an exception while rendering: %s' % force_unicode(e, errors='replace'))
17-            wrapped.source = node.source
18-            wrapped.exc_info = exc_info()
19-            raise wrapped
20         return result
21 
22 class DebugVariableNode(VariableNode):
23Index: tests/regressiontests/templates/tests.py
24===================================================================
25--- tests/regressiontests/templates/tests.py    (revision 10645)
26+++ tests/regressiontests/templates/tests.py    (working copy)
27@@ -158,7 +158,8 @@
28 
29     def test_url_reverse_no_settings_module(self):
30         # Regression test for #9005
31-        from django.template import Template, Context, TemplateSyntaxError
32+        from django.template import Template, Context
33+        from django.core.urlresolvers import NoReverseMatch
34 
35         old_settings_module = settings.SETTINGS_MODULE
36         old_template_debug = settings.TEMPLATE_DEBUG
37@@ -170,10 +171,10 @@
38         c = Context()
39         try:
40             rendered = t.render(c)
41-        except TemplateSyntaxError, e:
42+        except NoReverseMatch, e:
43             # Assert that we are getting the template syntax error and not the
44             # string encoding error.
45-            self.assertEquals(e.args[0], "Caught an exception while rendering: Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.")
46+            self.assertEquals(e.args[0], "Reverse for 'will_not_match' with arguments '()' and keyword arguments '{}' not found.")
47 
48         settings.SETTINGS_MODULE = old_settings_module
49         settings.TEMPLATE_DEBUG = old_template_debug