We also copy the instances over without using any events now, so that
the 'dirty' list on the new session remains unaffected.
+ - fixed bug which could arise when using session.begin_nested() in conjunction
+ with more than one level deep of enclosing session.begin() statements
+
- dialects
- MSSQL/PyODBC no longer has a global "set nocount on".
if bind in self.__connections:
return self.__connections[bind][0]
- if bind in self.__parent._connection_dict():
- (conn, trans, autoclose) = self.__parent.__connections[bind]
+ conn_dict = self.__parent._connection_dict()
+ if bind in conn_dict:
+ (conn, trans, autoclose) = conn_dict[bind]
self.__connections[conn] = self.__connections[bind.engine] = (conn, conn.begin_nested(), autoclose)
return conn
elif bind in self.__connections:
conn.close()
raise
+ @testing.supported('postgres', 'mysql')
+ @engines.close_open_connections
+ def test_heavy_nesting(self):
+ session = create_session(bind=testbase.db)
+
+ session.begin()
+ session.connection().execute("insert into users (user_name) values ('user1')")
+
+ session.begin()
+
+ session.begin_nested()
+
+ session.connection().execute("insert into users (user_name) values ('user2')")
+ assert session.connection().execute("select count(1) from users").scalar() == 2
+
+ session.rollback()
+ assert session.connection().execute("select count(1) from users").scalar() == 1
+ session.connection().execute("insert into users (user_name) values ('user3')")
+
+ session.commit()
+ assert session.connection().execute("select count(1) from users").scalar() == 2
+
+
@testing.supported('postgres', 'mysql')
@testing.exclude('mysql', '<', (5, 0, 3))
def test_twophase(self):