If I used Marshmallow to create a schema like this:
class TempSchema(Schema):
id = fields.Int()
email = fields.Str(required=True,
validate=validate.Email(error='Not a valid email address'))
password = fields.Str(required=True,
validate=[validate.Length(min=6, max=36)],
load_only=True)
and then I do something like:
temp = TempSchema()
temp.dumps({'email':123})
I'd expect an error but I get:
MarshalResult(data='{"email": "123"}', errors={})
Why isn't this or anything else showing up as an error?
Validation only happens on deserialization (using Schema.load
), not serialization (Schema.dump
).
data, errors = schema.load({'email': '123'})
print(errors)
# {'email': ['Not a valid email address'], 'password': ['Missing data for required field.']}
If you don't need the deserialized data, you can use Schema.validate
.
errors = schema.validate({'email': '123'})
print(errors)
# {'email': ['Not a valid email address'], 'password': ['Missing data for required field.']}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With