diff --git a/django/views/debug.py b/django/views/debug.py index c85b86c913e..68dba4b500a 100644 --- a/django/views/debug.py +++ b/django/views/debug.py @@ -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 = [] diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py index 1276f061fa9..bb5a45224db 100644 --- a/tests/view_tests/tests/test_debug.py +++ b/tests/view_tests/tests/test_debug.py @@ -391,6 +391,26 @@ class ExceptionReporterTests(SimpleTestCase): self.assertIn('

Request information

', html) self.assertNotIn('

Request data not supplied

', 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('

ValueError

', html) + self.assertIn('
Can't find my keys
', html) + self.assertIn('Exception Type:', html) + self.assertIn('Exception Value:', html) + self.assertIn('

Traceback ', html) + self.assertIn('

Request information

', html) + self.assertIn('

Request data not supplied

', html) + self.assertNotIn('During handling of the above exception', html) + def test_reporting_of_nested_exceptions(self): request = self.rf.get('/test_view/') try: