Skip to content

TypeError when using Enum columns with the Databricks dialect (all 2.0.x releases) #61

@sha16384

Description

@sha16384

Description

Any SQLAlchemy operation that involves an Enum-typed column with the Databricks dialect raises:

TypeError: String.__init__() got an unexpected keyword argument '_enums'

Steps to reproduce

 from sqlalchemy import create_engine, Column, Enum
 from sqlalchemy.orm import DeclarativeBase
 
 class Base(DeclarativeBase):
     pass
 
 class MyTable(Base):
     __tablename__ = "my_table"
     status = Column(Enum("A", "B", "C"), nullable=False)
 
 engine = create_engine("databricks://...")
 Base.metadata.create_all(engine)

Root cause

databricks-sqlalchemy registers DatabricksStringType as the colspec for sqlalchemy.String in the Databricks dialect. When SQLAlchemy adapts an Enum column (via Enum.adapt()), it internally passes _enums as a keyword argument to the target type's constructor. DatabricksStringType.__init__() does not accept **kwargs or _enums, causing the crash.

Environment

Affected versions: 2.0.1 – 2.0.9
SQLAlchemy: 2.0.x

Related issues

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