Skip to content

Commit

Permalink
Fixed #18169 -- NoReverseMatch not silenced if from block.super
Browse files Browse the repository at this point in the history
  • Loading branch information
akaariai committed May 31, 2013
1 parent 8490937 commit 369b6fa
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 2 deletions.
3 changes: 1 addition & 2 deletions django/core/urlresolvers.py
Expand Up @@ -75,8 +75,7 @@ class Resolver404(Http404):
pass pass


class NoReverseMatch(Exception): class NoReverseMatch(Exception):
# Don't make this raise an error when used in a template. pass
silent_variable_failure = True


def get_callable(lookup_view, can_fail=False): def get_callable(lookup_view, can_fail=False):
""" """
Expand Down
6 changes: 6 additions & 0 deletions docs/releases/1.6.txt
Expand Up @@ -616,6 +616,12 @@ Miscellaneous
stored as ``null``. Previously, storing a ``blank`` value in a field which stored as ``null``. Previously, storing a ``blank`` value in a field which
did not allow ``null`` would cause a database exception at runtime. 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 Features deprecated in 1.6
========================== ==========================


Expand Down
3 changes: 3 additions & 0 deletions tests/template_tests/templates/included_base.html
@@ -0,0 +1,3 @@
{% block content %}
{% block error_here %}{% endblock %}
{% endblock %}
11 changes: 11 additions & 0 deletions 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 %}
9 changes: 9 additions & 0 deletions tests/template_tests/tests.py
Expand Up @@ -444,6 +444,15 @@ def test_ifchanged_render_once(self):
output = template.render(Context({})) output = template.render(Context({}))
self.assertEqual(output, '1st time') 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): def test_templates(self):
template_tests = self.get_template_tests() template_tests = self.get_template_tests()
filter_tests = filters.get_filter_tests() filter_tests = filters.get_filter_tests()
Expand Down

0 comments on commit 369b6fa

Please sign in to comment.