Skip to content

Length validation error on Enum fields #673

@lafrech

Description

@lafrech

This looks similar to #54.

class Model(Base):
    __tablename__ = "table"

    field = sqla.Column(sqla.Enum(MyEnum, name="my_enum"))


class ModelSchema(AutoSchema):
    class Meta(AutoSchema.Meta):
        model = Model

    # Code works if this line is commented
    # field = ma.fields.Enum(MyEnum)

I'm getting this error on deserialization:

TypeError: object of type 'MyEnum' has no len()

SQLAlchemy does add a max length to the column and it seems like we're generating a max length validator and running it on the deserialized enum rather than the input string since validators apply after deserialization.

I'd drop the length validator since it is redundant anyway.

My code works if I uncomment the direct field declaration.

I didn't have time to investigate any further but I'm dropping this here for discussion.

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

    Issue actions