Marshmallow: Allow empty value for field

Created on 19 Apr 2016  路  2Comments  路  Source: marshmallow-code/marshmallow

Hello,

would you consider adding the ability to specify something like allow_empty=True (or False) when declaring a field like fields.Str? This would allow me to check for an empty string without having to code a validator for it (unless there is already another way of doing it that I'm missing...).

Kind regards,
Fabrizio

Most helpful comment

You can use the built-in Length validator to validate against empty strings:

from marshmallow import validate, fields
not_empty = validate.Length(min=1)

foo = fields.Str(validate=not_empty)

All 2 comments

You can use the built-in Length validator to validate against empty strings:

from marshmallow import validate, fields
not_empty = validate.Length(min=1)

foo = fields.Str(validate=not_empty)

I see. Cool, thank you :)

Was this page helpful?
0 / 5 - 0 ratings