1
0
mirror of https://github.com/django/django.git synced 2024-12-23 01:25:58 +00:00

Fixed #27956 -- Fixed display of errors in an {% extends %} child.

Thanks Ling-Xiao Yang for the report and test, and
Preston Timmons for the fix.
This commit is contained in:
Tim Graham 2017-03-25 08:22:12 -04:00 committed by GitHub
parent f42c7cc87b
commit e643ba8bcf
5 changed files with 27 additions and 4 deletions

View File

@ -203,14 +203,16 @@ class RenderContext(BaseContext):
return self.dicts[-1][key]
@contextmanager
def push_state(self, template):
def push_state(self, template, isolated_context=True):
initial = self.template
self.template = template
if isolated_context:
self.push()
try:
yield
finally:
self.template = initial
if isolated_context:
self.pop()

View File

@ -151,6 +151,7 @@ class ExtendsNode(Node):
# Call Template._render explicitly so the parser context stays
# the same.
with context.render_context.push_state(compiled_parent, isolated_context=False):
return compiled_parent._render(context)

View File

@ -0,0 +1,3 @@
{% extends "27956_parent.html" %}
{% block content %}{% endblock %}

View File

@ -0,0 +1,5 @@
{% load tag_27584 %}
{% badtag %}{% endbadtag %}
{% block content %}{% endblock %}

View File

@ -122,6 +122,18 @@ class TemplateTests(SimpleTestCase):
t.render(Context())
self.assertEqual(e.exception.template_debug['during'], '{% badtag %}')
def test_compile_tag_error_27956(self):
"""Errors in a child of {% extends %} are displayed correctly."""
engine = Engine(
app_dirs=True,
debug=True,
libraries={'tag_27584': 'template_tests.templatetags.tag_27584'},
)
t = engine.get_template('27956_child.html')
with self.assertRaises(TemplateSyntaxError) as e:
t.render(Context())
self.assertEqual(e.exception.template_debug['during'], '{% badtag %}')
def test_super_errors(self):
"""
#18169 -- NoReverseMatch should not be silence in block.super.