Skip to content

KeyError when reflecting mssql tables that contains indexes with non alphanumeric chars in field names #1770

Closed
@sqlalchemy-bot

Description

@sqlalchemy-bot
Collaborator

Migrated issue, originally created by Anonymous

I tried to reflect some tables I have in mssql but obtain the following error:

Traceback (most recent call last):
  File "/usr/local/Plone/public_test/bin/zopepy", line 146, in ?
    execfile(sys.argv[0](0))
  File "./test.py", line 11, in ?
    customer = Table('Bizak 26-03-2010$Customer', meta, autoload=True, autoload_with=engine)
  File "/usr/local/Plone/buildout-cache/eggs/SQLAlchemy-0.6beta3-py2.4.egg/sqlalchemy/schema.py", line 207, in __new__
    table._init(name, metadata, *args, **kw)
  File "/usr/local/Plone/buildout-cache/eggs/SQLAlchemy-0.6beta3-py2.4.egg/sqlalchemy/schema.py", line 253, in _init
    autoload_with.reflecttable(self, include_columns=include_columns)
  File "/usr/local/Plone/buildout-cache/eggs/SQLAlchemy-0.6beta3-py2.4.egg/sqlalchemy/engine/base.py", line 1588, in reflecttable
    self.dialect.reflecttable(conn, table, include_columns)
  File "/usr/local/Plone/buildout-cache/eggs/SQLAlchemy-0.6beta3-py2.4.egg/sqlalchemy/engine/default.py", line 206, in reflecttable
    return insp.reflecttable(table, include_columns)
  File "/usr/local/Plone/buildout-cache/eggs/SQLAlchemy-0.6beta3-py2.4.egg/sqlalchemy/engine/reflection.py", line 369, in reflecttable
    sa_schema.Index(name, *[table.columns[c](table.columns[c) for c in columns], 
  File "/usr/local/Plone/buildout-cache/eggs/SQLAlchemy-0.6beta3-py2.4.egg/sqlalchemy/util.py", line 730, in __getitem__
    return self._data[key](key)
KeyError: 'Search'

In my tests one of the values of rowindex_keys (dialect.mssql.base line 1105) was 'Search Name, No_' then applying
col_finder.findall('Search Name, No_') results in Name', No_'. Three fields!!! Actually there are two fields called 'Search Name' and 'No_'.

Attached you can find a patch to solve this.


Attachments: patch

Activity

sqlalchemy-bot

sqlalchemy-bot commented on Apr 18, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • set milestone to "0.6.xx"
sqlalchemy-bot

sqlalchemy-bot commented on Apr 18, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed assignee from "ram" to "empty"
sqlalchemy-bot

sqlalchemy-bot commented on Oct 23, 2010

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

Unfortunately the attached patch does not accommodate column names that have commas in them, which are reported by sp_helpindex with no unambiguous delineation. While I would wonder why a column name would ever have a comma in it, I wonder exactly the same thing about column names with spaces in them, and SQL Server accepts both, so therefore we have to worry about both.

9c0d6c0 contains a rewrite of get_indexes() which uses the sys. tables. This implies that index reflection is only supported for SQL Server 2005 and above, which I'm fine with (since index reflection is already not a typical need).

sqlalchemy-bot

sqlalchemy-bot commented on Oct 23, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed milestone from "0.6.xx" to "0.6.5"
  • changed status to closed
sqlalchemy-bot

sqlalchemy-bot commented on Dec 15, 2010

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

the query is not correct and test.engine.test_reflection fails for mssql.

sqlalchemy-bot

sqlalchemy-bot commented on Dec 15, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to reopened
sqlalchemy-bot

sqlalchemy-bot commented on Dec 15, 2010

@sqlalchemy-bot
CollaboratorAuthor

Michael Bayer (@zzzeek) wrote:

fixed again in 3e2fe1a

sqlalchemy-bot

sqlalchemy-bot commented on Dec 15, 2010

@sqlalchemy-bot
CollaboratorAuthor

Changes by Michael Bayer (@zzzeek):

  • changed status to closed
added this to the 0.6.5 milestone on Nov 27, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    SQL ServerMicrosoft SQL Server, e.g. mssqlbugSomething isn't workinghigh priority

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @sqlalchemy-bot

        Issue actions

          KeyError when reflecting mssql tables that contains indexes with non alphanumeric chars in field names · Issue #1770 · sqlalchemy/sqlalchemy