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

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

Open
ClementDelannoySlateDigital opened this issue Feb 5, 2025 · 1 comment

Comments

@ClementDelannoySlateDigital

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)
@ClementDelannoySlateDigital
Copy link
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
Labels
None yet
Development

No branches or pull requests

1 participant