MCPcopy
hub / github.com/django/django / test_prevent_rollback

Method test_prevent_rollback

tests/transactions/tests.py:216–229  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

214 self.assertSequenceEqual(Reporter.objects.all(), [])
215
216 def test_prevent_rollback(self):
217 with transaction.atomic():
218 reporter = Reporter.objects.create(first_name="Tintin")
219 sid = transaction.savepoint_create()
220 # trigger a database error inside an inner atomic without savepoint
221 with self.assertRaises(DatabaseError):
222 with transaction.atomic(savepoint=False):
223 with connection.cursor() as cursor:
224 cursor.execute("SELECT no_such_col FROM transactions_reporter")
225 # prevent atomic from rolling back since we're recovering manually
226 self.assertTrue(transaction.get_rollback())
227 transaction.set_rollback(False)
228 transaction.savepoint_rollback(sid)
229 self.assertSequenceEqual(Reporter.objects.all(), [reporter])
230
231 @skipUnlessDBFeature("can_release_savepoints")
232 def test_failure_on_exit_transaction(self):

Callers

nothing calls this directly

Calls 7

cursorMethod · 0.80
get_rollbackMethod · 0.80
set_rollbackMethod · 0.80
savepoint_rollbackMethod · 0.80
createMethod · 0.45
executeMethod · 0.45
allMethod · 0.45

Tested by

no test coverage detected