Skip to content

Autogenerate loses variants on TypeDecorator column with SQLAlchemy 2.0 #1167

Description

@mgorven

Describe the bug
An autogenerated migration adding a column using a TypeDecorator type and a with_variant() override loses the variants when using SQLAlchemy 2.0.

Expected behavior
The autogenerated migration includes the variants.

To Reproduce

With the following model definition and then alembic revision --autogenerate.

from sqlalchemy import Column, String, types
from sqlalchemy.dialects import postgresql
from sqlalchemy.orm import declarative_base

Base = declarative_base()

class UUID(types.TypeDecorator):
    impl = String

class Test(Base):
    __tablename__ = "test"
    id = Column(UUID().with_variant(postgresql.UUID(), "postgresql"), primary_key=True)

Error

With SQLAlchemy 1.4.46 the following migration is generated:

    op.create_table('test',
    sa.Column('id', models.UUID().with_variant(postgresql.UUID(), 'postgresql'), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )

Whereas with SQLALchemy 2.0.2 the with_variant() is missing:

    op.create_table('test',
    sa.Column('id', models.UUID(), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )

Versions.

  • OS: Linux
  • Python: 3.10
  • Alembic: 1.9.2
  • SQLAlchemy: 2.0.2
  • Database: SQLite
  • DBAPI: sqlite

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions