summaryrefslogtreecommitdiff
path: root/tests/transactions
diff options
context:
space:
mode:
authorAymeric Augustin <aymeric.augustin@m4x.org>2015-09-21 20:53:10 +0200
committerAymeric Augustin <aymeric.augustin@m4x.org>2015-09-21 22:21:53 +0200
commit91e9f1c972842284a94097e252307ce6ed1007a1 (patch)
tree02d46fd57f4443dad4bd0c8ef3f6dec023ad18f4 /tests/transactions
parent361254810eb8920978d69aa0fc074dbd40bfcc21 (diff)
downloaddjango-91e9f1c972842284a94097e252307ce6ed1007a1.tar.gz
Fixed #24921 -- set_autocommit(False) + ORM queries.
This commits lifts the restriction that the outermost atomic block must be declared with savepoint=False. This restriction was overly cautious. The logic that makes it safe not to create savepoints for inner blocks also applies to the outermost block when autocommit is disabled and a transaction is already active. This makes it possible to use the ORM after set_autocommit(False). Previously it didn't work because ORM write operations are protected with atomic(savepoint=False).
Diffstat (limited to 'tests/transactions')
-rw-r--r--tests/transactions/tests.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/tests/transactions/tests.py b/tests/transactions/tests.py
index dab406dbac..5d7851032f 100644
--- a/tests/transactions/tests.py
+++ b/tests/transactions/tests.py
@@ -398,16 +398,18 @@ class AtomicMiscTests(TransactionTestCase):
available_apps = []
def test_wrap_callable_instance(self):
- # Regression test for #20028
+ """#20028 -- Atomic must support wrapping callable instances."""
+
class Callable(object):
def __call__(self):
pass
+
# Must not raise an exception
transaction.atomic(Callable())
@skipUnlessDBFeature('can_release_savepoints')
def test_atomic_does_not_leak_savepoints_on_failure(self):
- # Regression test for #23074
+ """#23074 -- Savepoints must be released after rollback."""
# Expect an error when rolling back a savepoint that doesn't exist.
# Done outside of the transaction block to ensure proper recovery.
@@ -426,3 +428,14 @@ class AtomicMiscTests(TransactionTestCase):
# This is expected to fail because the savepoint no longer exists.
connection.savepoint_rollback(sid)
+
+ @skipIf(connection.features.autocommits_when_autocommit_is_off,
+ "This test requires a non-autocommit mode that doesn't autocommit.")
+ def test_orm_query_without_autocommit(self):
+ """#24921 -- ORM queries must be possible after set_autocommit(False)."""
+ transaction.set_autocommit(False)
+ try:
+ Reporter.objects.create(first_name="Tintin")
+ finally:
+ transaction.rollback()
+ transaction.set_autocommit(True)