Nested transactions/savepoints loose connections
Issue #942
resolved
When using nested transactions/savepoints, the associated connections seem to never get returned to the pool.
My patterin is:
t = session.begin_nested() session.commit()
When switching on echo=True
I do not see a commit actually go to the database, only a release savepoint
statement. Also, the connection is not returned to the pool, so that an open connection hangs around that isn't closed when I dispose the engine.
Comments (4)
-
Account Deleted -
Account Deleted - changed status to resolved
(original author: ants) Fixed in 9f366afdda4b508eb4ef3e626da2fec98ad04773
-
repo owner - removed milestone
Removing milestone: 0.4.xx (automated comment)
-
repo owner - edited description
- removed responsible
- Log in to comment
(original author: ants) You were probably using a transactional session (the default), which starts a transaction automatically on creation. When issuing a begin_nested() a subtransaction is actually started. So when you issue a commit() that nested transaction is commited (in practice, the savepoint is released), but the outer transaction stays open and correctly holds on to the connection.
When verifying this I noticed some other problems regarding session transactions. For example, begin(), begin_nested(), save(obj), commit() save(obj), commit() inserts the objects in two different transactions and the connection isn't returned to the pool for some reason (gc.collect() doesn't help). Another problem is that session.commit() and transaction.commit() don't get along very well.
The docs leave the transaction semantics of session kind of open. I'll figure out what the correct behaviour should be and fix/document it this weekend.