Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Failed to sync_enum_values for array of enums with default value #49

Closed
uriyyo opened this issue Dec 19, 2023 · 0 comments · Fixed by #50
Closed

Failed to sync_enum_values for array of enums with default value #49

uriyyo opened this issue Dec 19, 2023 · 0 comments · Fixed by #50

Comments

@uriyyo
Copy link
Contributor

uriyyo commented Dec 19, 2023

For instance, when I have a structure like this:

create type email_template_enum as enum
(
    'welcome',
    'password_reset',
    'email_verification'
);

create table users
(
    id              uuid                  default gen_random_uuid()           not null primary key,
    disabled_emails email_template_enum[] default '{}'::email_template_enum[] not null
);

And when I try to add another value to email_template_enum:

op.sync_enum_values(
    "public",
    "email_template_enum",
    [
        "welcome",
        "password_reset",
        "email_verification",
        "email_changed",
    ]
    [
        TableReference(
            "users",
            "disabled_emails",
            column_type=ColumnType.ARRAY,
            existing_server_default="'{}'::email_template_enum[]",
        ),
    ],
    enum_values_to_rename=[],
)

It will fail:

sqlalchemy.exc.DBAPIError: (sqlalchemy.dialects.postgresql.asyncpg.Error) <class 'asyncpg.exceptions.InvalidTextRepresentationError'>: invalid input value for enum email_template_enum: "{}"
[SQL: ALTER TABLE public.users ALTER COLUMN disabled_emails SET DEFAULT '{}'::email_template_enum]
(Background on this error at: https://sqlalche.me/e/20/dbapi)

Default value should be:

 '{}'::email_template_enum[]

Not:

 '{}'::email_template_enum
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant