marshmallow_enum icon indicating copy to clipboard operation
marshmallow_enum copied to clipboard

Make enum types pass validation

Open svenschwermer opened this issue 4 years ago • 0 comments

marshmallow 3.0.0 doesn't perform validation during dump[s]. In order to get the equivalent behaviour as before, validate must be called. However, this fails with "Enum name must be string" for the following MWE:

class MyEnum(Enum):
    a = 1

class MySchema(Schema):
    my_field = EnumField(MyEnum)

errors = MySchema().validate({"my_field": MyEnum.a})
assert not errors

Internally, validate calls _do_load which invokes _deserialize aon all fields. If there is nothing to deserialize, i.e. the type is already correct, don't do anything.

Signed-off-by: Sven Schwermer [email protected]

svenschwermer avatar Feb 18 '21 09:02 svenschwermer