marshmallow-code / marshmallow-code/marshmallow-sqlalchemy
Length validation error on Enum fields
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 580
- Forks
- 101
- Avg merge
- 7h 6m
- Merged PRs (30d)
- 3
Description
This looks similar to #54.
```py
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.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the provided SQLAlchemy Model and AutoSchema example, then trace how the generated length validator runs after Enum deserialization. Done means deserialization no longer applies an incompatible length check to the enum value and the behavior is covered by a regression test.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, sqlalchemy
- Domain
- backend, databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 35/100