]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- further fixes to no trans in progress, no trans ever for TLEngine, [ticket:1998]
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Dec 2010 15:04:23 +0000 (10:04 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 9 Dec 2010 15:04:23 +0000 (10:04 -0500)
lib/sqlalchemy/engine/threadlocal.py
test/engine/test_transaction.py

index c315b83ad8fbeb692474683c00814a7192dfa6e7..55f2c88cf2c2f176a2333728ae4ad28bfefc0e3c 100644 (file)
@@ -72,18 +72,21 @@ class TLEngine(base.Engine):
         self._connections.trans.append(self.contextual_connect().begin())
         
     def prepare(self):
-        if not self._connections.trans:
+        if not hasattr(self._connections, 'trans') or \
+            not self._connections.trans:
             return
         self._connections.trans[-1].prepare()
         
     def commit(self):
-        if not self._connections.trans:
+        if not hasattr(self._connections, 'trans') or \
+            not self._connections.trans:
             return
         trans = self._connections.trans.pop(-1)
         trans.commit()
         
     def rollback(self):
-        if not self._connections.trans:
+        if not hasattr(self._connections, 'trans') or \
+            not self._connections.trans:
             return
         trans = self._connections.trans.pop(-1)
         trans.rollback()
index a9045b3024901da28b527beef94563950e11edb2..72081071f60061aec7382219b75cc44075ecb354 100644 (file)
@@ -540,14 +540,38 @@ class TLTransactionTest(TestBase):
         tlengine.close()
     
     def test_rollback_no_trans(self):
+        tlengine = create_engine(testing.db.url, strategy="threadlocal")
+
+        # shouldn't fail
+        tlengine.rollback()
+        
+        tlengine.begin()
+        tlengine.rollback()
+
         # shouldn't fail
         tlengine.rollback()
 
     def test_commit_no_trans(self):
+        tlengine = create_engine(testing.db.url, strategy="threadlocal")
+
+        # shouldn't fail
+        tlengine.commit()
+
+        tlengine.begin()
+        tlengine.rollback()
+
         # shouldn't fail
         tlengine.commit()
 
     def test_prepare_no_trans(self):
+        tlengine = create_engine(testing.db.url, strategy="threadlocal")
+
+        # shouldn't fail
+        tlengine.prepare()
+
+        tlengine.begin()
+        tlengine.rollback()
+
         # shouldn't fail
         tlengine.prepare()