Lama Madan
Lama Madan

Reputation: 737

Python Marshmallow not detecting error in required field

I am using marshmallow to validate the data of APIs. But, it is not working for required field.

The following code works for length validation.

password = fields.String(validate = validate.Length(min=6))

But, required field is not working. It just ignore and continue without showing any error on that.

password = fields.String(required = True) //not working

Upvotes: 1

Views: 3773

Answers (1)

Chien Nguyen
Chien Nguyen

Reputation: 668

Please check this example:

from marshmallow import Schema, fields

class User(Schema):
    email = fields.Str()
    password = fields.Str(required=True)


User().load({'email': '[email protected]'}) # raise Exception
User().load({'email': '[email protected]', 'password': ''}) # Not raise exception

Your request.form always contain the field password but it will be blank.

Upvotes: 4

Related Questions