]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
TLConnection insures that it is used to create a transaction via the session when...
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 22 Jun 2006 19:46:44 +0000 (19:46 +0000)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 22 Jun 2006 19:46:44 +0000 (19:46 +0000)
CHANGES
lib/sqlalchemy/engine/threadlocal.py
test/engine/transaction.py

diff --git a/CHANGES b/CHANGES
index c4608bbf79a66b8d4f4d72293c2732fa15565b7a..0efbac11b6b51f8a35132bf8b4090af6e2b6df37 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,8 @@
 0.2.4
 - try/except when the mapper sets init.__name__ on a mapped class,
 supports python 2.3
+- fixed bug where threadlocal engine would still autocommit
+despite a transaction in progress
 - lazy load and deferred load operations require the parent object
 to be in a Session to do the operation; whereas before the operation
 would just return a blank list or None, it now raises an exception.
index 913c6425a29c48c255fd1e4a4ed3b4dd9d949331..d69a40755edd01b7b71e7b34e62c910d4d2b521c 100644 (file)
@@ -23,10 +23,12 @@ class TLSession(object):
         except AttributeError:
             pass
         self.__tcount = 0
-        
-    def begin(self):
+    def begin(self, tlconnection=None):
         if self.__tcount == 0:
-            self.__transaction = self.get_connection()
+            if tlconnection is None:
+                self.__transaction = self.get_connection()
+            else:
+                self.__transaction = tlconnection
             self.__trans = self.__transaction._begin()
         self.__tcount += 1
         return self.__trans
@@ -61,7 +63,7 @@ class TLConnection(base.Connection):
     def _begin(self):
         return base.Connection.begin(self)
     def begin(self):
-        return self.session.begin()
+        return self.session.begin(self)
     def close(self):
         if self.__opencount == 1:
             base.Connection.close(self)
index b8f8af96eddf32fae2edc258cf43b2d131085dfe..5f429761e7fb698167f34aa8ebaf6cbc69850535 100644 (file)
@@ -157,6 +157,38 @@ class TLTransactionTest(testbase.PersistTest):
         finally:
             external_connection.close()
 
+    @testbase.unsupported('mysql')
+    def testrollback_off_conn(self):
+        conn = tlengine.contextual_connect()
+        trans = conn.begin()
+        conn.execute(users.insert(), user_id=1, user_name='user1')
+        conn.execute(users.insert(), user_id=2, user_name='user2')
+        conn.execute(users.insert(), user_id=3, user_name='user3')
+        trans.rollback()
+
+        external_connection = tlengine.connect()
+        result = external_connection.execute("select * from query_users")
+        try:
+            assert len(result.fetchall()) == 0
+        finally:
+            external_connection.close()
+
+    @testbase.unsupported('mysql')
+    def testcommit_off_conn(self):
+        conn = tlengine.contextual_connect()
+        trans = conn.begin()
+        conn.execute(users.insert(), user_id=1, user_name='user1')
+        conn.execute(users.insert(), user_id=2, user_name='user2')
+        conn.execute(users.insert(), user_id=3, user_name='user3')
+        trans.commit()
+
+        external_connection = tlengine.connect()
+        result = external_connection.execute("select * from query_users")
+        try:
+            assert len(result.fetchall()) == 3
+        finally:
+            external_connection.close()
+        
     @testbase.unsupported('mysql', 'sqlite')
     def testnesting(self):
         """tests nesting of tranacstions"""