Ticket #28485: f51ded156e1b8ef8b59bc10b01100de6c3021ab3.patch

File f51ded156e1b8ef8b59bc10b01100de6c3021ab3.patch, 4.6 KB (added by Martin von Gagern, 7 years ago)

GitHub8880.patch

  • AUTHORS

    From f51ded156e1b8ef8b59bc10b01100de6c3021ab3 Mon Sep 17 00:00:00 2001
    From: Martin von Gagern <gagern@google.com>
    Date: Thu, 10 Aug 2017 02:01:33 +0100
    Subject: [PATCH] Show stack frames even if they are without source code
    
    So far we are silently dropping any stack frames that don't offer access to
    source code snippets, for whatever reason.  Actually having these frames
    included would be valuable, since they may still contain function names,
    file names and line numbers.
    ---
     AUTHORS                              |  1 +
     django/views/debug.py                | 36 ++++++++++++++++++++----------------
     tests/view_tests/tests/test_debug.py | 15 +++++++++++++++
     3 files changed, 36 insertions(+), 16 deletions(-)
    
    diff --git a/AUTHORS b/AUTHORS
    index 8fbf94582cc..ddbb1e67cae 100644
    a b answer newbie questions, and generally made Django that much better:  
    513513    Martin Kosír <martin@martinkosir.net>
    514514    Martin Mahner <http://www.mahner.org/>
    515515    Martin Maney <http://www.chipy.org/Martin_Maney>
     516    Martin von Gagern <gagern@google.com>
    516517    Mart Sõmermaa <http://mrts.pri.ee/>
    517518    Marty Alchin <gulopine@gamemusic.org>
    518519    masonsimon+django@gmail.com
  • django/views/debug.py

    diff --git a/django/views/debug.py b/django/views/debug.py
    index 9823b7dd8c3..fca137fd07f 100644
    a b def explicit_or_implicit_cause(exc_value):  
    418418            pre_context_lineno, pre_context, context_line, post_context = self._get_lines_from_file(
    419419                filename, lineno, 7, loader, module_name,
    420420            )
    421             if pre_context_lineno is not None:
    422                 frames.append({
    423                     'exc_cause': explicit_or_implicit_cause(exc_value),
    424                     'exc_cause_explicit': getattr(exc_value, '__cause__', True),
    425                     'tb': tb,
    426                     'type': 'django' if module_name.startswith('django.') else 'user',
    427                     'filename': filename,
    428                     'function': function,
    429                     'lineno': lineno + 1,
    430                     'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
    431                     'id': id(tb),
    432                     'pre_context': pre_context,
    433                     'context_line': context_line,
    434                     'post_context': post_context,
    435                     'pre_context_lineno': pre_context_lineno + 1,
    436                 })
     421            if pre_context_lineno is None:
     422                pre_context_lineno = lineno
     423                pre_context = []
     424                context_line = '<source code not available>'
     425                post_context = []
     426            frames.append({
     427                'exc_cause': explicit_or_implicit_cause(exc_value),
     428                'exc_cause_explicit': getattr(exc_value, '__cause__', True),
     429                'tb': tb,
     430                'type': 'django' if module_name.startswith('django.') else 'user',
     431                'filename': filename,
     432                'function': function,
     433                'lineno': lineno + 1,
     434                'vars': self.filter.get_traceback_frame_variables(self.request, tb.tb_frame),
     435                'id': id(tb),
     436                'pre_context': pre_context,
     437                'context_line': context_line,
     438                'post_context': post_context,
     439                'pre_context_lineno': pre_context_lineno + 1,
     440            })
    437441
    438442            # If the traceback for current exception is consumed, try the
    439443            # other exception.
  • tests/view_tests/tests/test_debug.py

    diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
    index a260f948e50..72e8cd6d3fe 100644
    a b def test_reporting_of_nested_exceptions(self):  
    375375        self.assertIn(implicit_exc.format("Second exception"), text)
    376376        self.assertEqual(3, text.count('<p>Final exception</p>'))
    377377
     378    def test_reporting_frames_without_source(self):
     379        try:
     380            source = "def funcName():\n    raise Error('Whoops')\nfuncName()"
     381            namespace = {}
     382            code = compile(source, "generated", "exec")
     383            exec(code, namespace)
     384        except Exception:
     385            exc_type, exc_value, tb = sys.exc_info()
     386        request = self.rf.get('/test_view/')
     387        reporter = ExceptionReporter(request, exc_type, exc_value, tb)
     388        html = reporter.get_traceback_html()
     389        self.assertIn("funcName", html)
     390        text = reporter.get_traceback_text()
     391        self.assertIn("funcName", text)
     392
    378393    def test_request_and_message(self):
    379394        "A message can be provided in addition to a request"
    380395        request = self.rf.get('/test_view/')
Back to Top