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

Default for deserialization parameter ("missing")? #115

sloria opened this Issue Dec 27, 2014 · 3 comments


None yet
2 participants

sloria commented Dec 27, 2014

There was some discussion in #45 over the addition of a field parameter (called missing) that would specify a default value for deserialization. We decided not to add the parameter because it would add complexity to the API when there are already hooks--including make_object and preprocessor--that could meet common use cases.

Some comments from that thread, snipped for brevity:


I think there may be a use case for a second default parameter for missing input values, similar to the missing parameter in colander:


...It seems to me that additional missing parameter is over-engineering. But setting default value for single field in preprocessor is bad too. In the case when there is a lot of such fields it requires repeated code for each field. So I guess that missing parameter is better for these cases.


I'm going to hold off on adding the missing parameter for now, to avoid the possibility of adding unneeded code...This isn't to say that the parameter won't be added in future releases. A compelling use case may arise that cannot be cleanly addressed using the existing hooks. Until we identify that use case, it will not be included.

Thanks to @rastikerdar, the issue is revived. I think there may be added value in the missing parameter. Opening this up for discussion.

@sloria sloria changed the title from Default for deserialization parameter: `missing` to Default for deserialization parameter ("missing")? Dec 27, 2014

@sloria sloria added the enhancement label Dec 27, 2014


This comment has been minimized.

rastikerdar commented Dec 27, 2014

Sometimes we need a callable missing:

afield = fields.DateTime(missing=lambda: datetime.datetime.utcnow())

And also needs to be aware of only and exclude list defined at schema initialization:

# for ...
    if name in self.exclude or (self.only and name not in self.only):
        continue # skip processing this missing field

This comment has been minimized.


sloria commented Jan 2, 2015

I agree. Thanks for the suggestions, @rastikerdar .


This comment has been minimized.


sloria commented Jan 30, 2015

Closed by #134

@sloria sloria closed this Jan 30, 2015

@sloria sloria added this to the 2.0-a milestone Jan 30, 2015

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment