Remove allow_blank parameter from String fields?
See original GitHub issueThe allow_blank
was added to address #76 . It is used to determine whether to allow the empty string as a valid value.
This parameter is technically redundant, since the same validation can be achieved using validate.Length
.
from marshamallow import fields, validate
not_blank = validate.Length(min=1, error='Field cannot be blank')
f = fields.Str(validate=not_blank)
f.deserialize('') # => Error: Field may not be blank.
I propose to remove the allow_blank
parameter, as it is unnecessary API.
Issue Analytics
- State:
- Created 9 years ago
- Reactions:2
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Not allow a blank character / space in a input form [duplicate]
Is it possible to not allow a blank character / space in a input form like below? <input type="text" value="" maxlength="30" name="email" ...
Read more >Solved: Re: allowBlank on select in multifield (Touch UI) ... - Adobe ...
It turns out there is an issue with the way AEM Touch UI multifield components update values. If you remove the last item,...
Read more >Parameters - GrapeCity
Allow Blank Value field : Select this check box if you want to allow blank values to be passed for the parameter. It...
Read more >Allow blank value(empty String) to be saved for a Custom Label
Then go to the label and in the value input field of the label press Ctrl+V to paste the Zero Width Space. Click...
Read more >AllowBlank="true" does not work - Ext.NET Forums
The text box where are thos Fields that has AllowBlank="true" become ... value of AllowBlank is "true", so it would be best to...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There is a valid use case for an option to disallow empty strings:
When you want to show a special error message for missing values including empty strings:
In that case, adding a Length(min=1) validator like this is problematic:
because an empty string would trigger two error messages (from both length validators):
I’ve just had a similar problem with an Integer-field. How would you solve the task to show two different messages for these two cases:
"12abc&$"
. You would like to show an error-message along the lines of “Only number-values are allowed.”Currently I don’t see a nice way to distinguish missing input from invalid numerical input, because marshmallow treats the empty string as non-missing. This is not a problem for JSON-submitted data (e.g. from Angular, …) of course. But for standard browser forms that are POSTed, this will be relevant.