[Django] #31672: debug error view shows no traceback if exc.__traceback__ is None for innermost exception

20 views
Skip to first unread message

Django

unread,
Jun 7, 2020, 1:07:47 AM6/7/20
to django-...@googlegroups.com
#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.

Django

unread,
Jun 7, 2020, 5:58:48 PM6/7/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: (none)
Type: Uncategorized | Status: new
Component: Error reporting | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
technical_500_response,traceback,chain| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

Here is a related (but different) issue about the traceback shown by the
debug error view ("debug error view doesn't respect
exc.__suppress_context__ (PEP 415)"):
https://code.djangoproject.com/ticket/31674

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:1>

Django

unread,
Jun 8, 2020, 5:17:22 AM6/8/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

Sure, I'll see if I can find time to put something together for this and
the others.

By the way, have there been any issues with people not receiving all email
notifications from `code.djangoproject.com`? It seems like I don't get
some of them (not even to my spam folder).

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:3>

Django

unread,
Oct 8, 2020, 10:46:56 AM10/8/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned

Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* has_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:5>

Django

unread,
Oct 12, 2020, 7:11:47 AM10/12/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Fixed by 78ae8cc5d8aff65afbf35947421a8a1aba13bfab.

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:8>

Django

unread,
Oct 12, 2020, 7:11:52 AM10/12/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed

Component: Error reporting | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by felixxm):

* status: assigned => closed
* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:9>

Django

unread,
Oct 12, 2020, 5:41:21 PM10/12/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed
Component: Error reporting | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Chris Jerdonek):

Thanks for fixing the issue!

I looked at the PR after this was merged and made a comment:
https://github.com/django/django/pull/13513#issuecomment-707355649

By the way, I didn't get another email about this ticket until after the
PR was merged and approved. I think it might be a good addition to your
process in general if you could CC the reporter on any PR or otherwise
notify them (maybe this could be done automatically) to ensure they also
have a chance to see it before it's merged. I know this isn't the first
time I didn't have a chance to see a fix for an issue I reported until
after it was merged. In many cases, the extra pair of eyes can help
because the original reporter may have insights the PR author doesn't have
since they spent the time finding and diagnosing it.

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:10>

Django

unread,
Oct 13, 2020, 12:20:52 AM10/13/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed
Component: Error reporting | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by felixxm):

Chris, thanks for comments. Reporters should get notifications about all
updates. I'm not sure why you didn't get them. 🤔

> In many cases, the extra pair of eyes can help because the original
reporter may have insights the PR author doesn't have since they spent the
time finding and diagnosing it.

Totally agreed, I will ping you directly in PRs in the future, thanks.

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:11>

Django

unread,
Oct 15, 2020, 2:24:41 PM10/15/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: new

Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"a492ccf0bc3da0b99c27b44e491ec3d6aabd5d3f" a492ccf0]:
{{{
#!CommitTicketReference repository=""
revision="a492ccf0bc3da0b99c27b44e491ec3d6aabd5d3f"
Refs #31672 -- Simplified ExceptionReporter.get_traceback_frames().
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:15>

Django

unread,
Nov 3, 2020, 5:55:29 PM11/3/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: new
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/13637 PR] to address
[https://code.djangoproject.com/ticket/31672#comment:13 Mariusz comment].

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:16>

Django

unread,
Nov 4, 2020, 1:15:03 AM11/4/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: new
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:17>

Django

unread,
Nov 4, 2020, 3:45:00 PM11/4/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: new
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:18>

Django

unread,
Nov 9, 2020, 3:30:58 AM11/9/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned

Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => assigned


* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:19>

Django

unread,
Nov 9, 2020, 11:36:54 AM11/9/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
technical_500_response,traceback,chain|
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Hasan Ramezani):

* needs_better_patch: 1 => 0


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:20>

Django

unread,
Nov 10, 2020, 7:25:04 AM11/10/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:21>

Django

unread,
Nov 10, 2020, 9:00:46 AM11/10/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: assigned
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"4cd77f97a2d30d58841041a73d277ec4bfb7b530" 4cd77f97]:
{{{
#!CommitTicketReference repository=""
revision="4cd77f97a2d30d58841041a73d277ec4bfb7b530"
Refs #31672 -- Made technical 500 debug page include exceptions without
tracebacks.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:22>

Django

unread,
Nov 10, 2020, 9:01:40 AM11/10/20
to django-...@googlegroups.com
#31672: debug error view shows no traceback if exc.__traceback__ is None for
innermost exception
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Hasan
Type: | Ramezani
Cleanup/optimization | Status: closed

Component: Error reporting | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
technical_500_response,traceback,chain| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: assigned => closed
* resolution: => fixed


--
Ticket URL: <https://code.djangoproject.com/ticket/31672#comment:23>

Reply all
Reply to author
Forward
0 new messages