1. Michael Bayer
  2. sqlalchemy
  3. Issues

Issues

Issue #3151 resolved

mssql+pymssql recently broken with SQL Azure

Daniel Halperin
created an issue

The issue is that the self.server_version_info struct is not being populated because SQL Azure changed their version string. The new string:

Microsoft SQL Azure (RTM) - 11.0.9216.62 
    Jul 18 2014 22:00:21 
    Copyright (c) Microsoft Corporation

The regex used by SQLAlchemy's mssql+pymssql dialect:

        m = re.match(
            r"Microsoft SQL Server.*? - (\d+).(\d+).(\d+).(\d+)", vers)

This does not match, which leads to a None version info, which breaks the code:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "sqlq/explain.py", line 30, in explain
    _do_explain(db, expl_db)
  File "sqlq/explain.py", line 13, in _do_explain
    with expl_db.connect() as connection:
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1779, in connect
    return self._connection_cls(self, **kwargs)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 60, in __init__
    self.__connection = connection or engine.raw_connection()
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/engine/base.py", line 1848, in raw_connection
    return self.pool.unique_connection()
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/pool.py", line 280, in unique_connection
    return _ConnectionFairy._checkout(self)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/pool.py", line 641, in _checkout
    fairy = _ConnectionRecord.checkout(pool)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/pool.py", line 440, in checkout
    rec = pool._do_get()
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/pool.py", line 961, in _do_get
    return self._create_connection()
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/pool.py", line 285, in _create_connection
    return _ConnectionRecord(self)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/pool.py", line 416, in __init__
    exec_once(self.connection, self)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 250, in exec_once
    self(*args, **kw)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/event/attr.py", line 260, in __call__
    fn(*args, **kw)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/util/langhelpers.py", line 1219, in go
    return once_fn(*arg, **kw)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/engine/strategies.py", line 165, in first_connect
    dialect.initialize(c)
  File "/Users/dhalperi/Envs/sdss-query/lib/python2.7/site-packages/sqlalchemy/dialects/mssql/base.py", line 1374, in initialize
    if self.server_version_info[0] not in list(range(8, 17)):
TypeError: 'NoneType' object has no attribute '__getitem__'

Comments (5)

  1. Michael Bayer repo owner

    can you confirm this patch works? thanks

    diff --git a/lib/sqlalchemy/dialects/mssql/pymssql.py b/lib/sqlalchemy/dialects/mssql/pymssql.py
    index 8f76336..b5a1bc5 100644
    --- a/lib/sqlalchemy/dialects/mssql/pymssql.py
    +++ b/lib/sqlalchemy/dialects/mssql/pymssql.py
    @@ -63,7 +63,7 @@ class MSDialect_pymssql(MSDialect):
         def _get_server_version_info(self, connection):
             vers = connection.scalar("select @@version")
             m = re.match(
    -            r"Microsoft SQL Server.*? - (\d+).(\d+).(\d+).(\d+)", vers)
    +            r"Microsoft .*? - (\d+).(\d+).(\d+).(\d+)", vers)
             if m:
                 return tuple(int(x) for x in m.group(1, 2, 3, 4))
             else:
    
  2. Log in to comment