mssql fails to reflect indexes referencing non-ascii column names
I'm encountering a SQL Server database with non-ascii column names (containing Icelandic characters). Autoload fails on indexes referencing such columns:
from sqlalchemy import *
some_url = 'mssql+pyodbc://someuser:somepass@/?Servername=Somename'
e = create_engine(some_url, encoding='utf8', convert_unicode=True)
metadata = MetaData(e)
tables = [metadata, autoload=True) for tn in e.table_names()](Table(tn,)
results in:
Traceback (most recent call last):
File "mssql_non_ascii_column_names.py", line 8, in <module>
tables = [metadata, autoload=True) for tn in e.table_names()](Table(tn,)
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/schema.py", line 265, in __new__
table._init(name, metadata, *args, **kw)
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/schema.py", line 335, in _init
self, include_columns
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/engine/base.py", line 2264, in run_callable
return conn.run_callable(callable_, *args, **kwargs)
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/engine/base.py", line 1894, in run_callable
return callable_(self, *args, **kwargs)
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/engine/default.py", line 254, in reflecttable
return insp.reflecttable(table, include_columns)
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/engine/reflection.py", line 470, in reflecttable
sa_schema.Index(name, *[table.columns[c](table.columns[c) for c in columns],
File "/opt/pyenv/FOO/lib/python2.5/site-packages/sqlalchemy/util/_collections.py", line 88, in __getitem__
return self._data[key](key)
KeyError: 'S\xc3\x96LUGENGI'
Attached patch fixes this by decoding the column names according to the dialect's self._decoder
if they aren't already unicode
.
I don't have a SQL Server with write access to run regression tests against, but at least this doesn't break any of the 46 tests that ./sqla_nose.py test.dialect.test_mssql
can run without a DB backend.
Comments (8)
-
Account Deleted -
repo owner gunnlaugur for the win ! do you need this in 0.6 also ?
-
Account Deleted Yep, not quite ready to move to 0.7 yet (and this fits equally neatly on both branches, hence the two patches).
-
repo owner - changed milestone to 0.6.9
-
Account Deleted Fixed patch against 0.6 branch (no self._decoder)
-
repo owner backport to 0.6.9 as well (I'm reversing how i assign milestones, otherwise the issue looks like an 0.6-only thing)
-
repo owner - changed status to resolved
8ad65d0ee114970338c8b668c280f3e95534e744 0ff337f29e3f1060a98338300fcecfc550936558
0.6 is patched, but note I'm not decided yet if I want to release 0.6.9. 0.6.8 has been quite stable and those who have issues typically move to 0.7.
-
repo owner - removed milestone
Removing milestone: 0.7.4 (automated comment)
- Log in to comment
Patch resolving this ticket against tip of default branch