]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Threadlocal engine methods rollback(), commit(),
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Dec 2010 18:46:29 +0000 (13:46 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 8 Dec 2010 18:46:29 +0000 (13:46 -0500)
prepare() won't raise if no transaction is in progress;
this was a regression introduced in 0.6.  [ticket:1998]

CHANGES
lib/sqlalchemy/engine/threadlocal.py
test/engine/test_transaction.py

diff --git a/CHANGES b/CHANGES
index a057509d1b7ce09d0c707c117328aa3679f96c86..6e884d41ef8b11e23bf7e0a48b6ede5796f50a2b 100644 (file)
--- 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]
index b6fa14af7f7aaa917c8724a0adc5255c672cf699..6b222680c26122cf443a52a627f50d57ae7c0a1b 100644 (file)
@@ -77,16 +77,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()
index 14d8bfd1b31dae51716882d1b50168e791bf8c8b..1e8c33a983531239753de6ae5fb12fd2241fa89b 100644 (file)
@@ -541,7 +541,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."""