-
-
Notifications
You must be signed in to change notification settings - Fork 629
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't fill empty fields with default value #1765
Comments
Update: solved my issue by adding a post_load activity: class ContactSchema(Schema):
"""Scheme for path `contacts`."""
links = fields.List(fields.Nested(LinksSchema))
contact_id = fields.Str(data_key='contactId')
name = fields.Str()
email = fields.Str(data_key='emailAddress')
phone = fields.Str(
data_key='phoneNumber',
missing='(no number available)',
default='(no number available)',
allow_none=True
)
archived = fields.Boolean()
@post_load
def no_number(self, item, *args, **kwargs):
if not item['phone'] or item['phone'] == '':
item['phone'] = '(no number available)'
return item Still open is the question why default or missing is not handled at all, when allow_none is set to False. |
The Using I proposed an API for customizing the values that are considered "missing" in #1381 . But that will require some thought...I'm still not sure it's a good idea. |
|
Just to be sure it is clear. missing is for deserialization, default for serialization. |
Ahaa! Got it, I just read the docs a thousand times, but I did not stumble over that parts, for any unknown reason. Thx, sorry for the inconveniences. |
Hi,
I'm currently out of ideas. I try to get rid of None's in my schema, but nothing seems to work.
Here's the schema:
Regardless what I try, neither the value of missing or default it taken. I also tried to use only either default or missing. If I set
allow_none=True
the schema is validated in any case, but the fieldphone
is unset or None. marshmallow is 3.10.0Any ideas on how to solve this? According the docs this is supposed to work, or am I wrong?
Regards, Thomas
The text was updated successfully, but these errors were encountered: