Fixed #31674 -- Made technical 500 debug page respect __suppress_context__.

This commit is contained in:
Tom Forbes 2020-07-13 08:01:59 +02:00 committed by Mariusz Felisiak
parent b7a438c7e2
commit f36862b69c
2 changed files with 22 additions and 1 deletions

View File

@ -396,8 +396,9 @@ class ExceptionReporter:
def get_traceback_frames(self):
def explicit_or_implicit_cause(exc_value):
explicit = getattr(exc_value, '__cause__', None)
suppress_context = getattr(exc_value, '__suppress_context__', None)
implicit = getattr(exc_value, '__context__', None)
return explicit or implicit
return explicit or (None if suppress_context else implicit)
# Get the exception and all its causes
exceptions = []

View File

@ -391,6 +391,26 @@ class ExceptionReporterTests(SimpleTestCase):
self.assertIn('<h2>Request information</h2>', html)
self.assertNotIn('<p>Request data not supplied</p>', html)
def test_suppressed_context(self):
try:
try:
raise RuntimeError("Can't find my keys")
except RuntimeError:
raise ValueError("Can't find my keys") from None
except ValueError:
exc_type, exc_value, tb = sys.exc_info()
reporter = ExceptionReporter(None, exc_type, exc_value, tb)
html = reporter.get_traceback_html()
self.assertInHTML('<h1>ValueError</h1>', html)
self.assertIn('<pre class="exception_value">Can&#x27;t find my keys</pre>', html)
self.assertIn('<th>Exception Type:</th>', html)
self.assertIn('<th>Exception Value:</th>', html)
self.assertIn('<h2>Traceback ', html)
self.assertIn('<h2>Request information</h2>', html)
self.assertIn('<p>Request data not supplied</p>', html)
self.assertNotIn('During handling of the above exception', html)
def test_reporting_of_nested_exceptions(self):
request = self.rf.get('/test_view/')
try: