Marshmallow: ValidationError does not get raised when None is loaded (Marshmallow 2.LatestX)

Created on 15 Feb 2019  路  2Comments  路  Source: marshmallow-code/marshmallow

Hi, I am not sure if this is a bug or intended behavior but here I go... So, currently I am using the latest version Marshmallow 2 (Sidenote: Do you guys recommend using the latest 3.X release candidate instead? I'm trying to use the latest stable version so decided to go with 2...) I have the following schema:

class SimpleSchema(Schema):
    my_field = String(required=True)

When I load data into the schema, if i do SimpleSchema().load({}), it obviously fails and raises a ValidationError (Yes, I am using strict=True in the Meta class) because my_field is undefined. However, if I pass SimpleSchema().load(None), it says ok and it works (raises no errors) even though required fields are not defined.

Is this some sort of bug or am I doing something wrong here? It certainly seems like weird behavior that may need to be fixed. Would love some feedback. Thanks for the great library and your precious time!

question

All 2 comments

This is fixed in marshmallow 3 (https://github.com/marshmallow-code/marshmallow/pull/725).

We kept the "wrong" behaviour in marshmallow 2 as people may be relying on it.

If you're starting a development, I'd recommend using marshmallow 3 even if it is still in RC. Don't expect too many changes... but be aware some may occur.

@lafrech Thanks a lot mate, will go with Marsh 3 then. G'day!

Was this page helpful?
0 / 5 - 0 ratings