1. Michael Manfre
  2. django-mssql
  3. Issues

Issues

Issue #12 resolved

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

Andre Terra
created an issue

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

{{{

!python

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

    See: http://msdn2.microsoft.com/en-us/library/ms174968.aspx
    """
    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)

    cursor.execute(sql)
    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 settings.py while running 'manage.py inspectdb' or rename the database column.

    Wiki macro error: Changeset 980f1e1b2287 not found.

  3. Log in to comment