From: Mike Bayer Date: Wed, 8 Dec 2010 18:46:29 +0000 (-0500) Subject: - Threadlocal engine methods rollback(), commit(), X-Git-Tag: rel_0_6_6~28 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d43ab796082da0a64dcb55113d15f05a3d48e7f9;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - Threadlocal engine methods rollback(), commit(), prepare() won't raise if no transaction is in progress; this was a regression introduced in 0.6. [ticket:1998] --- diff --git a/CHANGES b/CHANGES index a057509d1b..6e884d41ef 100644 --- a/CHANGES +++ b/CHANGES @@ -77,6 +77,10 @@ CHANGES "collections.Sequence" registration for RowProxy. [ticket:1871] + - Threadlocal engine methods rollback(), commit(), + prepare() won't raise if no transaction is in progress; + this was a regression introduced in 0.6. [ticket:1998] + - postgresql - Single element tuple expressions inside an IN clause parenthesize correctly, also from [ticket:1984] diff --git a/lib/sqlalchemy/engine/threadlocal.py b/lib/sqlalchemy/engine/threadlocal.py index ec2b4f302e..c315b83ad8 100644 --- a/lib/sqlalchemy/engine/threadlocal.py +++ b/lib/sqlalchemy/engine/threadlocal.py @@ -72,16 +72,22 @@ class TLEngine(base.Engine): self._connections.trans.append(self.contextual_connect().begin()) def prepare(self): + if not self._connections.trans: + return self._connections.trans[-1].prepare() def commit(self): + if not self._connections.trans: + return trans = self._connections.trans.pop(-1) trans.commit() def rollback(self): + if not self._connections.trans: + return trans = self._connections.trans.pop(-1) trans.rollback() - + def dispose(self): self._connections = util.threading.local() super(TLEngine, self).dispose() diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index f09c671641..a9045b3024 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -538,7 +538,19 @@ class TLTransactionTest(TestBase): # ensure tests start with engine closed tlengine.close() + + def test_rollback_no_trans(self): + # shouldn't fail + tlengine.rollback() + + def test_commit_no_trans(self): + # shouldn't fail + tlengine.commit() + def test_prepare_no_trans(self): + # shouldn't fail + tlengine.prepare() + def test_connection_close(self): """test that when connections are closed for real, transactions are rolled back and disposed."""