diff options
| author | Tom Forbes <tom@tomforb.es> | 2020-07-13 08:01:59 +0200 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-07-13 08:06:21 +0200 |
| commit | f36862b69c3325da8ba6892a6057bbd9470efd70 (patch) | |
| tree | fa4c2b2b27bba7c8b9ad402db1a795c2b0ef95a2 | |
| parent | b7a438c7e21cdcb26d47f1c1fc5afdc1b3d1a9ef (diff) | |
Fixed #31674 -- Made technical 500 debug page respect __suppress_context__.
| -rw-r--r-- | django/views/debug.py | 3 | ||||
| -rw-r--r-- | tests/view_tests/tests/test_debug.py | 20 |
2 files changed, 22 insertions, 1 deletions
diff --git a/django/views/debug.py b/django/views/debug.py index c85b86c913..68dba4b500 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 1276f061fa..bb5a45224d 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('<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: |
