]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- Fixed bug in execution_options() feature whereby the existing
authorMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2010 17:42:31 +0000 (13:42 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Wed, 7 Apr 2010 17:42:31 +0000 (13:42 -0400)
Transaction and other state information from the parent
connection would not be propagated to the sub-connection.

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

diff --git a/CHANGES b/CHANGES
index cfba6f4a42e10fad408578b2ed94e169955e4588..3ecac29edc4c4a5db32174121dd37d4d5ac081bd 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -69,6 +69,10 @@ CHANGES
 
   - Fixed an error in expression typing which caused an endless
     loop for expressions with two NULL types.
+  
+  - Fixed bug in execution_options() feature whereby the existing
+    Transaction and other state information from the parent 
+    connection would not be propagated to the sub-connection.
     
 - ext
   - the compiler extension now allows @compiles decorators
index dc42ed957734059e08b8821a3e14cb75c07a7045..f040ec92012cde1c4a66e8231c8090d5a30cb404 100644 (file)
@@ -794,6 +794,14 @@ class Connection(Connectable):
         """
 
         return self.engine.Connection(self.engine, self.__connection, _branch=True)
+
+    def _clone(self):
+        """Create a shallow copy of this Connection.
+
+        """
+        c = self.__class__.__new__(self.__class__)
+        c.__dict__ = self.__dict__.copy()
+        return c
     
     def execution_options(self, **opt):
         """ Set non-SQL options for the connection which take effect during execution.
@@ -811,9 +819,9 @@ class Connection(Connectable):
         :meth:`sqlalchemy.sql.expression.Executable.execution_options`.
 
         """
-        return self.engine.Connection(
-                    self.engine, self.__connection,
-                     _branch=self.__branch, _execution_options=opt)
+        c = self._clone()
+        c._execution_options = c._execution_options.union(opt)
+        return c
     
     @property
     def dialect(self):
index e8da89438151d7ca4a36d13a83822b64cd1c0e01..f6cb9a4731cd451daa3a86fdef0cdefa0ec2ea5c 100644 (file)
@@ -120,7 +120,18 @@ class TransactionTest(TestBase):
             finally:
                 connection.close()
 
-
+    def test_retains_through_options(self):
+        connection = testing.db.connect()
+        try:
+            transaction = connection.begin()
+            connection.execute(users.insert(), user_id=1, user_name='user1')
+            conn2 = connection.execution_options(dummy=True)
+            conn2.execute(users.insert(), user_id=2, user_name='user2')
+            transaction.rollback()
+            eq_(connection.scalar("select count(1) from query_users"), 0)
+        finally:
+            connection.close()
+        
     def test_nesting(self):
         connection = testing.db.connect()
         transaction = connection.begin()