Columns with '%' in them raise a TypeError when inspectdb is used.

Issue #12 resolved
Andre Terra
created an issue

The fix is as simple as changing sqlserver_ado.introspection.DatabaseIntrospection._is_auto_field to:



def _is_auto_field(self, cursor, table_name, column_name):
    """Check if a column is an identity column.

    if r'%' in column_name:
        column_name = column_name.replace(r'%', '_')
    sql = "SELECT COLUMNPROPERTY(OBJECT_ID(N'%s'), N'%s', 'IsIdentity')" % \
        (table_name, column_name)

    return cursor.fetchone()[0]


Comments (3)

  1. Andre Terra reporter

    Precisely. However, the code for _is_auto_field as it stands right now breaks when inspecting a table with a column that contains '%' because of Python's string interpolation.

    The if clause I've included replaces '%' with a '_' so that the following interpolation works as expected. There's probably a more elegant and comprehensive solution, as I was just looking for an immediate fix for my testing environment.

  2. Michael Manfre repo owner

    Fixed #12 - Documented known issue with inspectdb and column names with '%'

    When DEBUG = True, introspecting a table containing a column with a '%' in its name will result in "TypeError: not enough arguments for format string" being thrown by CursorDebugWrapper. The workaround is to set 'DEBUG = False' in while running ' inspectdb' or rename the database column.

    Wiki macro error: Changeset 980f1e1b2287 not found.

  3. Log in to comment