--- /dev/null
+.. change::
+ :tags: bug, mssql
+ :tickets: 4536
+ :versions: 1.3.1
+
+ A commit() is emitted after an isolation level change to SNAPSHOT, as both
+ pyodbc and pymssql open an implicit transaction which blocks subsequent SQL
+ from being emitted in the current transaction.
cursor = connection.cursor()
cursor.execute("SET TRANSACTION ISOLATION LEVEL %s" % level)
cursor.close()
+ if level == "SNAPSHOT":
+ connection.commit()
def get_isolation_level(self, connection):
if self.server_version_info < MS_2005_VERSION:
eq_(dialect._get_server_version_info(conn), expected)
+class RealIsolationLevelTest(fixtures.TestBase):
+ __only_on__ = "mssql"
+ __backend__ = True
+
+ @testing.provide_metadata
+ def test_isolation_level(self):
+ Table("test", self.metadata, Column("id", Integer)).create(
+ checkfirst=True
+ )
+
+ with testing.db.connect() as c:
+ default = testing.db.dialect.get_isolation_level(c.connection)
+
+ values = [
+ "READ UNCOMMITTED",
+ "READ COMMITTED",
+ "REPEATABLE READ",
+ "SERIALIZABLE",
+ "SNAPSHOT",
+ ]
+ for value in values:
+ with testing.db.connect() as c:
+ c.execution_options(isolation_level=value)
+
+ c.execute("SELECT TOP 10 * FROM test")
+
+ eq_(
+ testing.db.dialect.get_isolation_level(c.connection), value
+ )
+
+ with testing.db.connect() as c:
+ eq_(testing.db.dialect.get_isolation_level(c.connection), default)
+
+
class IsolationLevelDetectTest(fixtures.TestBase):
def _fixture(self, view):
class Error(Exception):