From: Mike Bayer Date: Wed, 7 Apr 2010 17:42:31 +0000 (-0400) Subject: - Fixed bug in execution_options() feature whereby the existing X-Git-Tag: rel_0_6_0~41^2~1 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=822a6b57869e0091f439125ef9593b6c55af8352;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git - 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. --- diff --git a/CHANGES b/CHANGES index cfba6f4a42..3ecac29edc 100644 --- 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 diff --git a/lib/sqlalchemy/engine/base.py b/lib/sqlalchemy/engine/base.py index dc42ed9577..f040ec9201 100644 --- a/lib/sqlalchemy/engine/base.py +++ b/lib/sqlalchemy/engine/base.py @@ -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): diff --git a/test/engine/test_transaction.py b/test/engine/test_transaction.py index e8da894381..f6cb9a4731 100644 --- a/test/engine/test_transaction.py +++ b/test/engine/test_transaction.py @@ -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()