summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTom Forbes <tom@tomforb.es>2019-05-28 19:06:39 +0100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2019-05-29 08:30:22 +0200
commitace0bec804d0bd74e1ecddbe3ea9a8b5b5d0a718 (patch)
tree613059486a39c15f6f5cfea671abe5797338d0a4
parent0f0d1cd7722238158011c7717d410fae37513ceb (diff)
[2.2.x] Fixed #30516 -- Fixed crash of autoreloader when re-raising exceptions with custom signature.
Regression in c8720e7696ca41f3262d5369365cc1bd72a216ca. Backport of 0344565179527d80990e2247e3be7c04aa8c43c8 from master
-rw-r--r--django/utils/autoreload.py2
-rw-r--r--docs/releases/2.2.2.txt3
-rw-r--r--tests/utils_tests/test_autoreload.py30
3 files changed, 34 insertions, 1 deletions
diff --git a/django/utils/autoreload.py b/django/utils/autoreload.py
index ade9abdfdf..35952d5631 100644
--- a/django/utils/autoreload.py
+++ b/django/utils/autoreload.py
@@ -74,7 +74,7 @@ def check_errors(fn):
def raise_last_exception():
global _exception
if _exception is not None:
- raise _exception[0](_exception[1]).with_traceback(_exception[2])
+ raise _exception[1]
def ensure_echo_on():
diff --git a/docs/releases/2.2.2.txt b/docs/releases/2.2.2.txt
index 08af175caa..e95fa343fc 100644
--- a/docs/releases/2.2.2.txt
+++ b/docs/releases/2.2.2.txt
@@ -25,3 +25,6 @@ Bugfixes
* Fixed crash of :class:`~django.contrib.postgres.aggregates.ArrayAgg` and
:class:`~django.contrib.postgres.aggregates.StringAgg` with ``ordering``
argument when used in a ``Subquery`` (:ticket:`30315`).
+
+* Fixed a regression in Django 2.2 that caused a crash of auto-reloader when
+ an exception with custom signature is raised (:ticket:`30516`).
diff --git a/tests/utils_tests/test_autoreload.py b/tests/utils_tests/test_autoreload.py
index 9253482e7b..82f7287fa8 100644
--- a/tests/utils_tests/test_autoreload.py
+++ b/tests/utils_tests/test_autoreload.py
@@ -293,6 +293,36 @@ class TestRaiseLastException(SimpleTestCase):
with self.assertRaisesMessage(MyException, 'Test Message'):
autoreload.raise_last_exception()
+ def test_raises_custom_exception(self):
+ class MyException(Exception):
+ def __init__(self, msg, extra_context):
+ super().__init__(msg)
+ self.extra_context = extra_context
+ # Create an exception.
+ try:
+ raise MyException('Test Message', 'extra context')
+ except MyException:
+ exc_info = sys.exc_info()
+
+ with mock.patch('django.utils.autoreload._exception', exc_info):
+ with self.assertRaisesMessage(MyException, 'Test Message'):
+ autoreload.raise_last_exception()
+
+ def test_raises_exception_with_context(self):
+ try:
+ raise Exception(2)
+ except Exception as e:
+ try:
+ raise Exception(1) from e
+ except Exception:
+ exc_info = sys.exc_info()
+
+ with mock.patch('django.utils.autoreload._exception', exc_info):
+ with self.assertRaises(Exception) as cm:
+ autoreload.raise_last_exception()
+ self.assertEqual(cm.exception.args[0], 1)
+ self.assertEqual(cm.exception.__cause__.args[0], 2)
+
class RestartWithReloaderTests(SimpleTestCase):
executable = '/usr/bin/python'