summaryrefslogtreecommitdiff
path: root/tests/transaction_hooks
diff options
context:
space:
mode:
authorKrishnaprasad MG <krishna@holvi.com>2025-12-15 15:39:06 +0100
committerJacob Walls <jacobtylerwalls@gmail.com>2025-12-19 12:58:29 -0500
commit7a2f35b1b755b20a1e4d290a88bf059e6897f798 (patch)
treefba0bbd7a6f6475645b8262f443652da5b5d1c58 /tests/transaction_hooks
parent60fecd1d445224fa00385f5f1fde75999da7bec8 (diff)
Fixed #36487 -- Fixed logger error message with partial callbacks.
Diffstat (limited to 'tests/transaction_hooks')
-rw-r--r--tests/transaction_hooks/tests.py47
1 files changed, 47 insertions, 0 deletions
diff --git a/tests/transaction_hooks/tests.py b/tests/transaction_hooks/tests.py
index 938e92575f..5390165072 100644
--- a/tests/transaction_hooks/tests.py
+++ b/tests/transaction_hooks/tests.py
@@ -1,3 +1,5 @@
+from functools import partial
+
from django.db import connection, transaction
from django.test import TransactionTestCase, skipUnlessDBFeature
@@ -63,6 +65,28 @@ class TestConnectionOnCommit(TransactionTestCase):
self.assertIsInstance(raised_exception, ForcedError)
self.assertEqual(str(raised_exception), "robust callback")
+ def test_robust_if_no_transaction_with_callback_as_partial(self):
+ def robust_callback():
+ raise ForcedError("robust callback")
+
+ robust_callback_partial = partial(robust_callback)
+
+ with self.assertLogs("django.db.backends.base", "ERROR") as cm:
+ transaction.on_commit(robust_callback_partial, robust=True)
+ self.do(1)
+
+ self.assertDone([1])
+ log_record = cm.records[0]
+ self.assertEqual(
+ log_record.getMessage(),
+ f"Error calling {robust_callback_partial} "
+ f"in on_commit() (robust callback).",
+ )
+ self.assertIsNotNone(log_record.exc_info)
+ raised_exception = log_record.exc_info[1]
+ self.assertIsInstance(raised_exception, ForcedError)
+ self.assertEqual(str(raised_exception), "robust callback")
+
def test_robust_transaction(self):
def robust_callback():
raise ForcedError("robust callback")
@@ -84,6 +108,29 @@ class TestConnectionOnCommit(TransactionTestCase):
self.assertIsInstance(raised_exception, ForcedError)
self.assertEqual(str(raised_exception), "robust callback")
+ def test_robust_transaction_with_callback_as_partial(self):
+ def robust_callback():
+ raise ForcedError("robust callback")
+
+ robust_callback_partial = partial(robust_callback)
+
+ with self.assertLogs("django.db.backends", "ERROR") as cm:
+ with transaction.atomic():
+ transaction.on_commit(robust_callback_partial, robust=True)
+ self.do(1)
+
+ self.assertDone([1])
+ log_record = cm.records[0]
+ self.assertEqual(
+ log_record.getMessage(),
+ f"Error calling {robust_callback_partial} in on_commit() during "
+ "transaction (robust callback).",
+ )
+ self.assertIsNotNone(log_record.exc_info)
+ raised_exception = log_record.exc_info[1]
+ self.assertIsInstance(raised_exception, ForcedError)
+ self.assertEqual(str(raised_exception), "robust callback")
+
def test_delays_execution_until_after_transaction_commit(self):
with transaction.atomic():
self.do(1)