question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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

See original GitHub issue

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={})

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Comments:7 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
lucasvocommented, Jun 3, 2016

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).

0reactions
deckar01commented, Aug 2, 2021

Marshmallow 3.x no longer validates on dump, so the original issue no longer applies. https://github.com/marshmallow-code/marshmallow/issues/713 is a similar use case, and includes some examples that could work around this in marshmallow 2.x.

class OptionalUrl(fields.Url):
    def _serialize(self, value, attr, obj):
        if value == '':
            return ''
        return super()._serialize(value, attr, obj)
Read more comments on GitHub >

github_iconTop Results From Across the Web

Fields — marshmallow 3.19.0 documentation
Allows you to replace nested data with one of the data's fields. ... If an empty set, any non-falsy value will deserialize to...
Read more >
URL filter - Fortinet Documentation Library
URL filter is also called static URL filter. By adding specific URLs with patterns containing text and regular expressions, FortiGate can allow, block,...
Read more >
Postfix Configuration Parameters
The Postfix main.cf configuration file specifies a very small subset of all the parameters that control the operation of the Postfix mail system....
Read more >
Cannot bind argument to parameter because it is an empty ...
Probably a late answer, but in case others have a similar issue. In my case, it was an array of strings. It was...
Read more >
curl.1 the man page
You can specify any amount of URLs on the command line. ... "HOST2" and "PORT2" may also be the empty string, meaning "use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found