Marshmallow: Allow blank for all string types (url, email, ...) on dumping too

Created on 1 Feb 2015  路  3Comments  路  Source: marshmallow-code/marshmallow

allow_blank works only on load for fields.URL or fields.Email not dump:

from marshmallow import Schema, fields
class Test(Schema):
    url = fields.URL(allow_blank=True)

# '2.0.0-dev'
Test().dump({'url': ''})

returns:
MarshalResult(data={u'url': None}, errors={u'url': [u'"" is not a valid URL.']})

I think it should return:
MarshalResult(data={u'url': u''}, errors={})

Most helpful comment

I just found this PR: https://github.com/marshmallow-code/marshmallow/issues/167

But the change to remove allow_blank is missing from the changelog here: http://marshmallow.readthedocs.io/en/latest/changelog.html#changelog - would probably be helpful. (I was on 2.3 and used allow_blank extensively, this now just failed silently).

All 3 comments

+1. I think you are correct about the desired behavior here. Will fix this.

@sloria This doesn't seem to be fixed. Was this change reverted? I tried to find any evidence of this in the master branch but I can't find the changes in this commit or any evidence of allow_blank as valid argument for validators.Email

I just found this PR: https://github.com/marshmallow-code/marshmallow/issues/167

But the change to remove allow_blank is missing from the changelog here: http://marshmallow.readthedocs.io/en/latest/changelog.html#changelog - would probably be helpful. (I was on 2.3 and used allow_blank extensively, this now just failed silently).

Was this page helpful?
0 / 5 - 0 ratings

Related issues

imhoffd picture imhoffd  路  3Comments

j4k0bk picture j4k0bk  路  3Comments

lassandroan picture lassandroan  路  3Comments

ambye85 picture ambye85  路  4Comments

agatheblues picture agatheblues  路  3Comments