From 9273cdd6387bdf2182e595bdd5144a1792e9e1a4 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Thu, 12 Apr 2012 14:38:52 -0400 Subject: - [bug] If conn.begin() fails when calling "with engine.begin()", the newly acquired Connection is closed explicitly before propagating the exception onward normally. --- test/engine/test_execute.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'test/engine') diff --git a/test/engine/test_execute.py b/test/engine/test_execute.py index 6bdbf4227..610f5e42b 100644 --- a/test/engine/test_execute.py +++ b/test/engine/test_execute.py @@ -358,6 +358,23 @@ class ConvenienceExecuteTest(fixtures.TablesTest): testing.run_as_contextmanager(ctx, fn, 5, value=8) self._assert_fn(5, value=8) + def test_transaction_engine_ctx_begin_fails(self): + engine = engines.testing_engine() + class MockConnection(Connection): + closed = False + def begin(self): + raise Exception("boom") + + def close(self): + MockConnection.closed = True + engine._connection_cls = MockConnection + fn = self._trans_fn() + assert_raises( + Exception, + engine.begin + ) + assert MockConnection.closed + def test_transaction_engine_ctx_rollback(self): fn = self._trans_rollback_fn() ctx = testing.db.begin() -- cgit v1.2.1