Skip to content

bug: mssql backend fails to resolve schema for user-defined types #11837

@kolatat

Description

@kolatat

What happened?

The MSSQL backend fails when the query result contains a user-defined type (UDT). When I use .sql() on the mssql backend:

ibis.mssql.connect(...).sql('SELECT someFieldWithUDTResult FROM someTable')

exception 'NoneType' object has no attribute 'lower' is thrown. This occurs because .sql() tries to resolve the schema using mssql._get_schema_using_query() using this statement:

query = f"""
SELECT
name,
is_nullable,
system_type_name,
precision,
scale,
error_number,
error_message
FROM sys.dm_exec_describe_first_result_set(N{tsql}, NULL, 0)
ORDER BY column_ordinal
""" # noqa: S608

relying on the system_type_name column from sys.dm_exec_describe_first_result_set. According to Microsoft documentation, system_type_name returns NULL for user-defined types. When this None value is passed to the SQL compiler TypeMapper, it results in the exception when

def from_string(cls, text: str, nullable: bool | None = None) -> dt.DataType:
if dtype := cls.unknown_type_strings.get(text.lower()):
return dtype

calls text.lower() but text is None.

What version of ibis are you using?

10.8.0

What backend(s) are you using, if any?

MSSQL

Relevant log output

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIncorrect behavior inside of ibis

    Type

    No type

    Projects

    Status

    backlog

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions