Skip to content
This repository was archived by the owner on Oct 19, 2022. It is now read-only.

Make enum types pass validation#46

Open
svenschwermer wants to merge 1 commit intojustanr:next-releasefrom
svenschwermer:next-release
Open

Make enum types pass validation#46
svenschwermer wants to merge 1 commit intojustanr:next-releasefrom
svenschwermer:next-release

Conversation

@svenschwermer
Copy link
Copy Markdown

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 sven.schwermer@disruptive-technologies.com

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 <sven.schwermer@disruptive-technologies.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant