mirror of
				https://github.com/django/django.git
				synced 2025-10-31 09:41:08 +00:00 
			
		
		
		
	[2.2.x] Fixed #30516 -- Fixed crash of autoreloader when re-raising exceptions with custom signature.
Regression inc8720e7696. Backport of0344565179from master
This commit is contained in:
		
				
					committed by
					
						 Mariusz Felisiak
						Mariusz Felisiak
					
				
			
			
				
	
			
			
			
						parent
						
							0f0d1cd772
						
					
				
				
					commit
					ace0bec804
				
			| @@ -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(): | ||||
|   | ||||
| @@ -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`). | ||||
|   | ||||
| @@ -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' | ||||
|   | ||||
		Reference in New Issue
	
	Block a user