[Django] #31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)

12 views
Skip to first unread message

Django

unread,
Jun 7, 2020, 5:54:36 PM6/7/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------------+------------------------
Reporter: Chris Jerdonek | Owner: (none)
Type: Uncategorized | Status: new
Component: Error reporting | Version: 3.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------------+------------------------
Consider the following view that raises an exception:

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

def get(self, request, *args, **kwargs):
try:
raise RuntimeError('my error')
except Exception as exc:
raise ValueError('my new error') from None
}}}

Even though the `raise` is `from None`, unlike the traceback Python shows,
the debug error view still shows the `RuntimeError`.

This is because the `explicit_or_implicit_cause()` function inside
`get_traceback_frames()` doesn't respect `exc.__suppress_context__`, which
was introduced in Python 3.3's PEP 415:
https://github.com/django/django/blob/38a21f2d9ed4f556af934498ec6a242f6a20418a/django/views/debug.py#L392

{{{
#!python
def get_traceback_frames(self):
def explicit_or_implicit_cause(exc_value):
explicit = getattr(exc_value, '__cause__', None)
implicit = getattr(exc_value, '__context__', None)
return explicit or implicit
}}}

Instead, it should be something more like (simplifying also for Python 3):

{{{
#!python
def explicit_or_implicit_cause(exc_value):
return (
exc_value.__cause__ or
(None if exc_value.__suppress_context__ else
exc_value.__context__)
)
}}}

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

Django

unread,
Jun 7, 2020, 5:58:08 PM6/7/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
---------------------------------+--------------------------------------

Reporter: Chris Jerdonek | Owner: (none)
Type: Uncategorized | Status: new
Component: Error reporting | Version: 3.0
Severity: Normal | Resolution:

Keywords: | Triage Stage: 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 shows no traceback if
exc.__traceback__ is None for innermost exception"):
https://code.djangoproject.com/ticket/31672

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

Django

unread,
Jun 7, 2020, 6:10:19 PM6/7/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------+-------------------------------------

Reporter: Chris Jerdonek | Owner: (none)
Type: Uncategorized | Status: new
Component: Error reporting | Version: 3.0
Severity: Normal | Resolution:
Keywords: | Triage Stage:
technical_500_response, | Unreviewed
traceback, chain,suppress_context |

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Chris Jerdonek):

* keywords: => technical_500_response, traceback, chain,suppress_context


--
Ticket URL: <https://code.djangoproject.com/ticket/31674#comment:2>

Django

unread,
Jun 8, 2020, 12:21:13 AM6/8/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------+-------------------------------------

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,suppress_context |

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

* version: 3.0 => master
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

Thanks Chris. Would you like to prepare a patch?

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

Django

unread,
Jul 11, 2020, 6:26:16 PM7/11/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned

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

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

* owner: (none) => Tom Forbes
* status: new => assigned
* has_patch: 0 => 1


Comment:

PR: https://github.com/django/django/pull/13176

--
Ticket URL: <https://code.djangoproject.com/ticket/31674#comment:4>

Django

unread,
Jul 13, 2020, 2:10:55 AM7/13/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: assigned
Component: Error reporting | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
technical_500_response, | checkin
traceback, chain,suppress_context |
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


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

Django

unread,
Jul 13, 2020, 4:13:27 AM7/13/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: closed

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

Keywords: | Triage Stage: Ready for
technical_500_response, | checkin
traceback, chain,suppress_context |
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


Comment:

Fixed in f36862b69c3325da8ba6892a6057bbd9470efd70.

--
Ticket URL: <https://code.djangoproject.com/ticket/31674#comment:6>

Django

unread,
Oct 12, 2020, 7:10:28 AM10/12/20
to django-...@googlegroups.com
#31674: debug error view doesn't respect exc.__suppress_context__ (PEP 415)
-------------------------------------+-------------------------------------
Reporter: Chris Jerdonek | Owner: Tom
Type: | Forbes
Cleanup/optimization | Status: closed
Component: Error reporting | Version: master
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
technical_500_response, | checkin
traceback, chain,suppress_context |
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:"78ae8cc5d8aff65afbf35947421a8a1aba13bfab" 78ae8cc5]:
{{{
#!CommitTicketReference repository=""
revision="78ae8cc5d8aff65afbf35947421a8a1aba13bfab"
Fixed #31674 -- Fixed displaying traceback in technical 500 debug page.

Previously, the technical 500 debug page didn't contain a traceback
when the exception chain contained an exception without traceback.

Thanks Chris Jerdonek for the report.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31674#comment:7>

Reply all
Reply to author
Forward
0 new messages