mirror of
https://github.com/django/django.git
synced 2024-12-23 01:25:58 +00:00
Fixed #31674 -- Made technical 500 debug page respect __suppress_context__.
This commit is contained in:
parent
b7a438c7e2
commit
f36862b69c
@ -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 = []
|
||||
|
@ -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'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:
|
||||
|
Loading…
Reference in New Issue
Block a user