Thanks to visit codestin.com
Credit goes to github.com

Skip to content

DatabaseWrapper has no data_types #128

@chris-nlnz

Description

@chris-nlnz

Have an issue using django-pyodbc 1.0.0 with Django 1.8.15.

When saving (inserting) an object to a pyodbc database I get a TypeError when pyodbc tries to get the pk_db_type (compiler.py line 533):

# mangle SQL to return ID from insert
# http://msdn.microsoft.com/en-us/library/ms177564.aspx
if self.return_id and self.connection.features.can_return_id_from_insert:
    col = self.connection.ops.quote_name(meta.pk.db_column or meta.pk.get_attname())
    # Determine datatype for use with the table variable that will return the inserted ID
    pk_db_type = _re_data_type_terminator.split(meta.pk.db_type(self.connection))[0]

Problem is that the django.db.models.fields.Field.db_type method in Django 1.8.15 tries to get the data_type from a different place than Django 1.7 did:

# Django 1.7
data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")
try:
    return connection.creation.data_types[self.get_internal_type()] % data
except KeyError:
    return None

# Django 1.8
data = DictWrapper(self.__dict__, connection.ops.quote_name, "qn_")
try:
    return connection.data_types[self.get_internal_type()] % data
except KeyError:
    return None

Looking at pyodbc's code I see there is a data_types attribute on the DatabaseCreation model, but not on the DatabaseWrapper, whereas it seems to be the other way around with Django's built in DB engines. So this call fails as connection.data_types doesn't have any types in it, returns None and the regexp split fails as it's not a string.

Hope that makes sense, I don't know too much about django-pyodbc/Django database engine internals apart from what I discovered today so I apologise if I have misunderstood anything here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions