summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/dialects
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2018-06-18 17:12:56 +0300
committerMike Bayer <mike_mp@zzzcomputing.com>2018-06-25 18:35:41 -0400
commite2913f65c4e5720394105584c69e7b9e8c2d373c (patch)
treec2de43a28f49f43031176153e34d76319c734949 /lib/sqlalchemy/dialects
parentc99345ee9994c3ea2a5e6536cc3365f18d017cc1 (diff)
downloadsqlalchemy-e2913f65c4e5720394105584c69e7b9e8c2d373c.tar.gz
Fix UnboundLocalError in mssql during isolation level grab
Fixed issue within the SQL Server dialect under Python 3 where when running against a non-standard SQL server database that does not contain either the "sys.dm_exec_sessions" or "sys.dm_pdw_nodes_exec_sessions" views, leading to a failure to fetch the isolation level, the error raise would fail due to an UnboundLocalError. Fixes: #4273 Co-authored-by: wikiped <wikiped@yandex.ru> Change-Id: I39877c1f65f9cf8602fb1dceaf03072357759564
Diffstat (limited to 'lib/sqlalchemy/dialects')
-rw-r--r--lib/sqlalchemy/dialects/mssql/base.py19
1 files changed, 12 insertions, 7 deletions
diff --git a/lib/sqlalchemy/dialects/mssql/base.py b/lib/sqlalchemy/dialects/mssql/base.py
index 2975a6c69..bc3905535 100644
--- a/lib/sqlalchemy/dialects/mssql/base.py
+++ b/lib/sqlalchemy/dialects/mssql/base.py
@@ -1897,6 +1897,8 @@ class MSDialect(default.DefaultDialect):
raise NotImplementedError(
"Can't fetch isolation level prior to SQL Server 2005")
+ last_error = None
+
views = ("sys.dm_exec_sessions", "sys.dm_pdw_nodes_exec_sessions")
for view in views:
cursor = connection.cursor()
@@ -1914,19 +1916,22 @@ class MSDialect(default.DefaultDialect):
""" % view)
val = cursor.fetchone()[0]
except self.dbapi.Error as err:
+ # Python3 scoping rules
+ last_error = err
continue
else:
return val.upper()
finally:
cursor.close()
+ else:
+ util.warn(
+ "Could not fetch transaction isolation level, "
+ "tried views: %s; final error was: %s" % (views, last_error))
- util.warn(
- "Could not fetch transaction isolation level, "
- "tried views: %s; final error was: %s" % (views, err))
- raise NotImplementedError(
- "Can't fetch isolation level on this particular "
- "SQL Server version"
- )
+ raise NotImplementedError(
+ "Can't fetch isolation level on this particular "
+ "SQL Server version"
+ )
def initialize(self, connection):
super(MSDialect, self).initialize(connection)