From 369b6fab25b55ceb363ba2a8cb7e0f1a88ef8f8d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anssi=20K=C3=A4=C3=A4ri=C3=A4inen?= Date: Thu, 30 May 2013 10:25:58 +0300 Subject: [PATCH] Fixed #18169 -- NoReverseMatch not silenced if from block.super --- django/core/urlresolvers.py | 3 +-- docs/releases/1.6.txt | 6 ++++++ tests/template_tests/templates/included_base.html | 3 +++ tests/template_tests/templates/included_content.html | 11 +++++++++++ tests/template_tests/tests.py | 9 +++++++++ 5 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/template_tests/templates/included_base.html create mode 100644 tests/template_tests/templates/included_content.html diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py index 5f314ff490d..d58f2a9fa38 100644 --- a/django/core/urlresolvers.py +++ b/django/core/urlresolvers.py @@ -75,8 +75,7 @@ class Resolver404(Http404): pass class NoReverseMatch(Exception): - # Don't make this raise an error when used in a template. - silent_variable_failure = True + pass def get_callable(lookup_view, can_fail=False): """ diff --git a/docs/releases/1.6.txt b/docs/releases/1.6.txt index 91dda667f17..cd665a775ef 100644 --- a/docs/releases/1.6.txt +++ b/docs/releases/1.6.txt @@ -616,6 +616,12 @@ Miscellaneous stored as ``null``. Previously, storing a ``blank`` value in a field which did not allow ``null`` would cause a database exception at runtime. +* If a :class:`~django.core.urlresolvers.NoReverseMatch` exception is risen + from a method when rendering a template it is not silenced. For example + {{ obj.view_href }} will cause template rendering to fail if view_href() + raises NoReverseMatch. There is no change to {% url %} tag, it causes + template rendering to fail like always when NoReverseMatch is risen. + Features deprecated in 1.6 ========================== diff --git a/tests/template_tests/templates/included_base.html b/tests/template_tests/templates/included_base.html new file mode 100644 index 00000000000..eae222cf9da --- /dev/null +++ b/tests/template_tests/templates/included_base.html @@ -0,0 +1,3 @@ +{% block content %} + {% block error_here %}{% endblock %} +{% endblock %} diff --git a/tests/template_tests/templates/included_content.html b/tests/template_tests/templates/included_content.html new file mode 100644 index 00000000000..bfc87c04252 --- /dev/null +++ b/tests/template_tests/templates/included_content.html @@ -0,0 +1,11 @@ +{% extends "included_base.html" %} + +{% block content %} + content + {{ block.super }} +{% endblock %} + +{% block error_here %} + error here + {% url "non_existing_url" %} +{% endblock %} diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 2aeaee9464a..15668e00c0c 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -444,6 +444,15 @@ class Templates(TestCase): output = template.render(Context({})) self.assertEqual(output, '1st time') + def test_super_errors(self): + """ + Test behavior of the raise errors into included blocks. + See #18169 + """ + t = loader.get_template('included_content.html') + with self.assertRaises(urlresolvers.NoReverseMatch): + t.render(Context({})) + def test_templates(self): template_tests = self.get_template_tests() filter_tests = filters.get_filter_tests()