]> 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 6b222680c26122cf443a52a627f50d57ae7c0a1b..adcce08c6d15ec1a6dc425ffafed9434ead4af0b 100644 (file)
@@ -77,18 +77,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 1e8c33a983531239753de6ae5fb12fd2241fa89b..01a561d7b8544fde6b48fd29496fa4ccc968b975 100644 (file)
@@ -543,14 +543,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()