Ticket #19827: 19827-stacktrace_on_reraise.2.diff

File 19827-stacktrace_on_reraise.2.diff, 2.3 KB (added by regebro, 12 years ago)

Replacement based on feedback from claudep

  • django/template/defaulttags.py

    diff --git a/django/template/defaulttags.py b/django/template/defaulttags.py
    index c1ca947..e79347e 100644
    a b class URLNode(Node):  
    409409        url = ''
    410410        try:
    411411            url = reverse(view_name, args=args, kwargs=kwargs, current_app=context.current_app)
    412         except NoReverseMatch as e:
     412        except NoReverseMatch:
     413            exc_info = sys.exc_info()
    413414            if settings.SETTINGS_MODULE:
    414415                project_name = settings.SETTINGS_MODULE.split('.')[0]
    415416                try:
    class URLNode(Node):  
    421422                        # Re-raise the original exception, not the one with
    422423                        # the path relative to the project. This makes a
    423424                        # better error message.
    424                         raise e
     425                        six.reraise(*exc_info)
    425426            else:
    426427                if self.asvar is None:
    427                     raise e
     428                    raise
    428429
    429430        if self.asvar:
    430431            context[self.asvar] = url
  • tests/regressiontests/templates/tests.py

    diff --git a/tests/regressiontests/templates/tests.py b/tests/regressiontests/templates/tests.py
    index 02d3460..267d5cc 100644
    a b class Templates(TestCase):  
    372372        with self.assertRaises(urlresolvers.NoReverseMatch):
    373373            t.render(c)
    374374
     375    @override_settings(TEMPLATE_STRING_IF_INVALID='%s is invalid', SETTINGS_MODULE='also_something')
     376    def test_url_reverse_view_name(self):
     377        # Regression test for #19827
     378        from django.template import Template, Context
     379
     380        t = Template('{% url will_not_match %}')
     381        c = Context()
     382        try:
     383            t.render(c)
     384        except urlresolvers.NoReverseMatch:
     385            tb = sys.exc_info()[2]
     386            depth = 0
     387            while tb.tb_next is not None:
     388                tb = tb.tb_next
     389                depth += 1
     390            self.assertTrue(depth > 5, "The traceback context was lost when reraising the traceback. See #19827")
     391
    375392    def test_url_explicit_exception_for_old_syntax_at_run_time(self):
    376393        # Regression test for #19280
    377394        t = Template('{% url path.to.view %}')      # not quoted = old syntax
Back to Top