summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorMichael van Tellingen <michaelvantellingen@gmail.com>2013-02-14 09:45:55 +0100
committerAymeric Augustin <aymeric.augustin@m4x.org>2013-02-14 10:22:59 +0100
commit138de533ff677b470a1e7b4b6ff084a5b7a7444b (patch)
treef7be64117ff4d463ba6a7f28701c319f1d091843 /django
parentf1029b308f3ea967a5d93aea2b730671898a56f5 (diff)
Fixed #19819 - Improved template filter errors handling.
Wrap the Parser.compile_filter method call with a try/except and call the newly added Parser.compile_filter_error(). Overwrite this method in the DebugParser to throw the correct error. Since this error was otherwise catched by the compile_function try/except block the debugger highlighted the wrong line.
Diffstat (limited to 'django')
-rw-r--r--django/template/base.py9
-rw-r--r--django/template/debug.py4
2 files changed, 12 insertions, 1 deletions
diff --git a/django/template/base.py b/django/template/base.py
index 0a2b2c9437..9577d586d8 100644
--- a/django/template/base.py
+++ b/django/template/base.py
@@ -250,7 +250,11 @@ class Parser(object):
elif token.token_type == 1: # TOKEN_VAR
if not token.contents:
self.empty_variable(token)
- filter_expression = self.compile_filter(token.contents)
+ try:
+ filter_expression = self.compile_filter(token.contents)
+ except TemplateSyntaxError as e:
+ if not self.compile_filter_error(token, e):
+ raise
var_node = self.create_variable_node(filter_expression)
self.extend_nodelist(nodelist, var_node, token)
elif token.token_type == 2: # TOKEN_BLOCK
@@ -330,6 +334,9 @@ class Parser(object):
def unclosed_block_tag(self, parse_until):
raise self.error(None, "Unclosed tags: %s " % ', '.join(parse_until))
+ def compile_filter_error(self, token, e):
+ pass
+
def compile_function_error(self, token, e):
pass
diff --git a/django/template/debug.py b/django/template/debug.py
index c7ac007b48..043dd91b4e 100644
--- a/django/template/debug.py
+++ b/django/template/debug.py
@@ -64,6 +64,10 @@ class DebugParser(Parser):
msg = "Unclosed tag '%s'. Looking for one of: %s " % (command, ', '.join(parse_until))
raise self.source_error(source, msg)
+ def compile_filter_error(self, token, e):
+ if not hasattr(e, 'django_template_source'):
+ e.django_template_source = token.source
+
def compile_function_error(self, token, e):
if not hasattr(e, 'django_template_source'):
e.django_template_source = token.source