mirror of
https://github.com/django/django.git
synced 2025-11-19 19:24:46 +00:00
Merge 7c6b03752f into 1ce6e78dd4
This commit is contained in:
commit
a605aa9583
4 changed files with 66 additions and 10 deletions
|
|
@ -4,6 +4,7 @@ import threading
|
|||
import traceback
|
||||
import unittest
|
||||
import warnings
|
||||
from functools import partial
|
||||
from io import StringIO
|
||||
from unittest import mock
|
||||
|
||||
|
|
@ -2145,6 +2146,35 @@ class CaptureOnCommitCallbacksTests(TestCase):
|
|||
self.assertIsInstance(raised_exception, MyException)
|
||||
self.assertEqual(str(raised_exception), "robust callback")
|
||||
|
||||
def test_execute_robust_with_callback_as_partial(self):
|
||||
class MyException(Exception):
|
||||
pass
|
||||
|
||||
def hook():
|
||||
self.callback_called = True
|
||||
raise MyException("robust callback")
|
||||
|
||||
hook_partial = partial(hook)
|
||||
|
||||
with self.assertLogs("django.test", "ERROR") as cm:
|
||||
with self.captureOnCommitCallbacks(execute=True) as callbacks:
|
||||
transaction.on_commit(hook_partial, robust=True)
|
||||
|
||||
self.assertEqual(len(callbacks), 1)
|
||||
self.assertIs(self.callback_called, True)
|
||||
|
||||
log_record = cm.records[0]
|
||||
self.assertRegex(
|
||||
log_record.getMessage(),
|
||||
r"Error calling functools\.partial\(<function CaptureOnCommitCallbacksTests"
|
||||
r"\.test_execute_robust_with_callback_as_partial\.<locals>\.hook"
|
||||
r" at .+>\) in on_commit\(\) \(robust callback\)\.",
|
||||
)
|
||||
self.assertIsNotNone(log_record.exc_info)
|
||||
raised_exception = log_record.exc_info[1]
|
||||
self.assertIsInstance(raised_exception, MyException)
|
||||
self.assertEqual(str(raised_exception), "robust callback")
|
||||
|
||||
|
||||
class DisallowedDatabaseQueriesTests(SimpleTestCase):
|
||||
def test_disallowed_database_connections(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue