summaryrefslogtreecommitdiff
path: root/test/orm
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2020-05-14 12:50:11 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2020-05-17 16:32:22 -0400
commit0e53221eef50b3274841fbd1eb41e32f5dfc4e69 (patch)
treee1c13d067b0db5e0aeee8b934dc0f934154ef9f3 /test/orm
parent79de84b25e87bbb7fa94f0dd513b4abc76e05a7e (diff)
downloadsqlalchemy-0e53221eef50b3274841fbd1eb41e32f5dfc4e69.tar.gz
Update transaction / connection handling
step one, do away with __connection attribute and using awkward AttributeError logic step two, move all management of "connection._transaction" into the transaction objects themselves where it's easier to follow. build MarkerTransaction that takes the role of "do-nothing block" new connection datamodel is: connection._transaction, always a root, connection._nested_transaction, always a nested. nested transactions still chain to each other as this is still sort of necessary but they consider the root transaction separately, and the marker transactions not at all. introduce new InvalidRequestError subclass PendingRollbackError. Apply to connection and session for all cases where a transaction needs to be rolled back before continuing. Within Connection, both PendingRollbackError as well as ResourceClosedError are now raised directly without being handled by handle_dbapi_error(); this removes these two exception cases from the handle_error event handler as well as from StatementError wrapping, as these two exceptions are not statement oriented and are instead programmatic issues, that the application is failing to handle database errors properly. Revise savepoints so that when a release fails, they set themselves as inactive so that their rollback() method does not throw another exception. Give savepoints another go on MySQL, can't get release working however get support for basic round trip going Fixes: #5327 Change-Id: Ia3cbbf56d4882fcc7980f90519412f1711fae74d
Diffstat (limited to 'test/orm')
-rw-r--r--test/orm/test_transaction.py27
1 files changed, 22 insertions, 5 deletions
diff --git a/test/orm/test_transaction.py b/test/orm/test_transaction.py
index 78a62199a..22e7363b0 100644
--- a/test/orm/test_transaction.py
+++ b/test/orm/test_transaction.py
@@ -367,13 +367,25 @@ class SessionTransactionTest(fixtures.RemovesEvents, FixtureTest):
sess.add(u)
sess.flush()
c1 = sess.connection(User)
+ dbapi_conn = c1.connection
+ assert dbapi_conn.is_valid
sess.invalidate()
- assert c1.invalidated
+
+ # Connection object is closed
+ assert c1.closed
+
+ # "invalidated" is not part of "closed" state
+ assert not c1.invalidated
+
+ # but the DBAPI conn (really ConnectionFairy)
+ # is invalidated
+ assert not dbapi_conn.is_valid
eq_(sess.query(User).all(), [])
c2 = sess.connection(User)
assert not c2.invalidated
+ assert c2.connection.is_valid
def test_subtransaction_on_noautocommit(self):
User, users = self.classes.User, self.tables.users
@@ -859,7 +871,7 @@ class SessionTransactionTest(fixtures.RemovesEvents, FixtureTest):
except Exception:
trans2.rollback(_capture_exception=True)
assert_raises_message(
- sa_exc.InvalidRequestError,
+ sa_exc.PendingRollbackError,
r"This Session's transaction has been rolled back due to a "
r"previous exception during flush. To begin a new transaction "
r"with this Session, first issue Session.rollback\(\). "
@@ -1001,7 +1013,7 @@ class SessionTransactionTest(fixtures.RemovesEvents, FixtureTest):
for i in range(5):
assert_raises_message(
- sa_exc.InvalidRequestError,
+ sa_exc.PendingRollbackError,
"^This Session's transaction has been "
r"rolled back due to a previous exception "
"during flush. To "
@@ -1037,7 +1049,7 @@ class SessionTransactionTest(fixtures.RemovesEvents, FixtureTest):
with expect_warnings(".*during handling of a previous exception.*"):
session.begin_nested()
- savepoint = session.connection()._transaction._savepoint
+ savepoint = session.connection()._nested_transaction._savepoint
# force the savepoint to disappear
session.connection().dialect.do_release_savepoint(
@@ -1708,7 +1720,12 @@ class SavepointTest(_LocalFixture):
nested_trans._do_commit()
is_(s.transaction, trans)
- assert_raises(sa_exc.DBAPIError, s.rollback)
+
+ with expect_warnings("nested transaction already deassociated"):
+ # this previously would raise
+ # "savepoint "sa_savepoint_1" does not exist", however as of
+ # #5327 the savepoint already knows it's inactive
+ s.rollback()
assert u1 not in s.new