diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-12 13:09:15 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2020-06-12 20:28:37 -0400 |
| commit | 5624430eb1d07c68d0931bc89f7146bc003fde19 (patch) | |
| tree | 2bfa7f881dec583d0c72f617222e17e9d900ff20 /test | |
| parent | dbaf82d258cc12d92ef28de4677d147fdb7808fd (diff) | |
| download | sqlalchemy-5624430eb1d07c68d0931bc89f7146bc003fde19.tar.gz | |
Warn when transaction context manager ends on inactive transaction
if .rollback() or .commit() is called inside the transaction
context manager, the transaction object is deactivated.
the context manager continues but will not be able to correctly
fulfill it's closing state. Ensure a warning is emitted when
this happens.
Change-Id: I8fc3a73f7c21575dda5bcbd6fb74ddb679771630
Diffstat (limited to 'test')
| -rw-r--r-- | test/engine/test_transaction.py | 21 |
1 files changed, 20 insertions, 1 deletions
diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index 164604cd6..b82d143f9 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -320,6 +320,22 @@ class TransactionTest(fixtures.TestBase): 1, ) + def test_deactivated_warning_ctxmanager(self, local_connection): + with expect_warnings( + "transaction already deassociated from connection" + ): + with local_connection.begin() as trans: + trans.rollback() + + @testing.requires.savepoints + def test_deactivated_savepoint_warning_ctxmanager(self, local_connection): + with expect_warnings( + "nested transaction already deassociated from connection" + ): + with local_connection.begin(): + with local_connection.begin_nested() as savepoint: + savepoint.rollback() + def test_commit_fails_flat(self, local_connection): connection = local_connection @@ -355,7 +371,10 @@ class TransactionTest(fixtures.TestBase): t1 = transaction[0] assert not t1.is_active - t1.rollback() # no error + with expect_warnings( + "transaction already deassociated from connection" + ): + t1.rollback() # no error @testing.requires.savepoints_w_release def test_savepoint_rollback_fails_flat(self, local_connection): |
