Skip to content

Array of enums not generating Enums #454

@coby-astsec

Description

@coby-astsec

Things to check first

  • I have searched the existing issues and didn't find my bug already reported there

  • I have checked that my bug is still present in the latest release

Sqlacodegen version

4.0.0rc2

SQLAlchemy version

v2.0.43

RDBMS vendor

PostgreSQL

What happened?

When generating models from types with enums as arrays, the type is not converted into an Enum:

class MyTable(Base):
    __tablename__ = 'my_table'
    __table_args__ = (
        PrimaryKeyConstraint('id', name='my_table_pkey'),
        {'schema': 'c'}
    )

    id: Mapped[int] = mapped_column(Integer, primary_key=True)
    my_enum: Mapped[list[str]] = mapped_column(ARRAY(Enum('a', 'b', name='my_enum', schema='c', _create_events=False)), nullable=False)

I would expect it to generate something like:

    my_enum: Mapped[list[MyEnum]] = mapped_column(ARRAY(Enum(MyEnum, schema='c', _create_events=False)), nullable=False)

Database schema for reproducing the bug

CREATE SCHEMA c;
CREATE TYPE c.my_enum AS ENUM (
    'a',
    'b'
);
CREATE TABLE c.my_table (
    id INT PRIMARY KEY,
    my_enum c.my_enum[] NOT NULL
);

Metadata

Metadata

Assignees

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions