summaryrefslogtreecommitdiff
path: root/test/engine
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2019-06-07 11:19:23 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2019-06-10 12:56:32 -0400
commit85568fc596c301563270efe217715f14aea8aa19 (patch)
tree7ff10cfbaa8b5079b30a852e7a256cbd08ea8ffc /test/engine
parentb0bf421f1b12eeedd77ec6c39df8e5e6cc1fcc3f (diff)
downloadsqlalchemy-85568fc596c301563270efe217715f14aea8aa19.tar.gz
Don't discard inactive transaction until it is explicitly rolled back
The :class:`.Connection` object will now not clear a rolled-back transaction until the outermost transaction is explicitly rolled back. This is essentially the same behavior that the ORM :class:`.Session` has had for a long time, where an explicit call to ``.rollback()`` on all enclosing transactions is required for the transaction to logically clear, even though the DBAPI-level transaction has already been rolled back. The new behavior helps with situations such as the "ORM rollback test suite" pattern where the test suite rolls the transaction back within the ORM scope, but the test harness which seeks to control the scope of the transaction externally does not expect a new transaction to start implicitly. Fixes: #4712 Change-Id: Ibc6c8d981cff31594a5d26dd5203fd9cfcea1c74
Diffstat (limited to 'test/engine')
-rw-r--r--test/engine/test_transaction.py30
1 files changed, 28 insertions, 2 deletions
diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py
index 81f86089b..f6f5cd9fc 100644
--- a/test/engine/test_transaction.py
+++ b/test/engine/test_transaction.py
@@ -75,7 +75,6 @@ class TransactionTest(fixtures.TestBase):
connection.execute(users.insert(), user_id=2, user_name="user2")
connection.execute(users.insert(), user_id=3, user_name="user3")
transaction.rollback()
-
result = connection.execute("select * from query_users")
assert len(result.fetchall()) == 0
connection.close()
@@ -167,11 +166,28 @@ class TransactionTest(fixtures.TestBase):
branched.execute(users.insert(), user_id=2, user_name="user2")
nested.rollback()
assert not connection.in_transaction()
- eq_(connection.scalar("select count(*) from query_users"), 0)
+
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "This connection is on an inactive transaction. Please",
+ connection.execute,
+ "select 1",
+ )
finally:
connection.close()
+ def test_inactive_due_to_subtransaction_no_commit(self):
+ connection = testing.db.connect()
+ trans = connection.begin()
+ trans2 = connection.begin()
+ trans2.rollback()
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "This transaction is inactive",
+ trans.commit,
+ )
+
def test_branch_autorollback(self):
connection = testing.db.connect()
try:
@@ -406,9 +422,19 @@ class TransactionTest(fixtures.TestBase):
connection.execute(users.insert(), user_id=1, user_name="user1")
trans2 = connection.begin_nested()
connection.execute(users.insert(), user_id=2, user_name="user2")
+
trans3 = connection.begin()
connection.execute(users.insert(), user_id=3, user_name="user3")
trans3.rollback()
+
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "This connection is on an inactive savepoint transaction.",
+ connection.execute,
+ "select 1",
+ )
+ trans2.rollback()
+
connection.execute(users.insert(), user_id=4, user_name="user4")
transaction.commit()
eq_(