#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
               Reporter:  Chris      |          Owner:  (none)
  Jerdonek                           |
                   Type:             |         Status:  new
  Uncategorized                      |
              Component:  Error      |        Version:  3.0
  reporting                          |       Keywords:
               Severity:  Normal     |  technical_500_response,traceback,chain
           Triage Stage:             |      Has patch:  0
  Unreviewed                         |
    Needs documentation:  0          |    Needs tests:  0
Patch needs improvement:  0          |  Easy pickings:  0
                  UI/UX:  0          |
-------------------------------------+-------------------------------------
 Consider this test view which raises an exception:

 {{{
 #!python
 class TestView(View):

     def get(self, request, *args, **kwargs):
         try:
             raise RuntimeError('my error')
         except Exception as exc:
             # Uncommenting these two lines causes the debug
             # server error view not to show **any** portion
             # of the traceback.
             # new_exc = RuntimeError('my context')
             # exc.__context__ = new_exc

             raise
 }}}

 If the indicated lines are uncommented, then the debug error view shows no
 traceback info at all.

 This is because `django.views.debug.get_traceback_frames()` starts at the
 innermost exception in the chain, and then stops adding frames when it
 encounters the first exception with `None`-valued
 `exc_value.__traceback__`:
 
https://github.com/django/django/blob/38a21f2d9ed4f556af934498ec6a242f6a20418a/django/views/debug.py#L391

 {{{
 #!python
 exc_value = exceptions.pop()
 tb = self.tb if not exceptions else exc_value.__traceback__

 while tb is not None:
     # Get frame.
     ...
     frames.append({
         ...
     })

     # If the traceback for current exception is consumed, try the
     # other exception.
     if not tb.tb_next and exceptions:
         exc_value = exceptions.pop()
         tb = exc_value.__traceback__
     else:
         tb = tb.tb_next

 return frames
 }}}

 It would probably be better and simpler if instead the while loop were
 structured to iterate over every exception in the chain no matter what,
 and include traceback info only for those exceptions with non-`None`
 `__traceback__`. In other words, something like the following:

 {{{
 #!python
 while exceptions:
     exc_value = exceptions.pop()
     # Returns placeholder frame with no `tb` info if
     # `exc_value.__traceback__ is None`.
     exc_frames = self.get_traceback_frames(exc_value)
     frames.extend(exc_frames)
 }}}

 This way, the debug error view would always show the complete exception
 chain, even if some exceptions in the chain have a `None`-valued traceback
 attribute.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31672>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/052.c501d9ab745c9f2ab6bd9c1c1ec0b74d%40djangoproject.com.

Reply via email to