Skip to content

Can't update enum column from the flask-admin edit form #2597

Open
@ClementDelannoySlateDigital

Description

Hello, thank you in advance for your help

The error message:
Failed to update record. (psycopg2.errors.InvalidTextRepresentation) invalid input value for enum enumname: "enumvalue" LINE 1:

My model:

class EnumName(enum.Enum):
enumvalue1 = 1
enumvalue2 = 2

EnumName.enumvalue1.label = "enumvalue1"
EnumName.enumvalue2.label = "enumvalue2"

I have nothing weird in my ModelView, I just want to display my column and make that enum editable.
In the edit panel, I have a dropdown displaying the values. I can modify them.
But when I click on the Save button, this error appears:

Failed to update record. (psycopg2.errors.InvalidTextRepresentation) invalid input value for enum enumname: "enumvalue" LINE 1:

In the callstack serverside, there is also a mention to sqlalchemy.exc.DataError

I guess it tries to update with a string instead of an enumvalue. But I don't get the internal with psycopg2.

I'm sorry if this ticket has already been discussed, but I can't find any information other than weird unsustainable workaround, and I'd like to avoid this kind of stuff 😄

Environment:

  • Python version: 3.12.8
  • Flask version: 3.1.0
  • Flask-Admin version: 1.6.1
  • WTForms: 3.1.2 (I fixed that due to a bug with 3.2.0, that's why I put that here)

Activity

ClementDelannoySlateDigital

ClementDelannoySlateDigital commented on Feb 5, 2025

@ClementDelannoySlateDigital
Author

Oh, and this column was created using alembic.op on a postgresql database:

    with op.batch_alter_table('tablename', schema=None) as batch_op:
        batch_op.add_column(sa.Column('columnname', sa.Enum('enumvalue1', 'enumvalue2', name='enumname', nullable=False, server_default='enumvalue1'))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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

      Participants

      @ClementDelannoySlateDigital

      Issue actions

        Can't update enum column from the flask-admin edit form · Issue #2597 · pallets-eco/flask-admin