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

Proposal: Add `default`-normalization rule #131

Closed
funkyfuture opened this Issue Jul 20, 2015 · 3 comments

Comments

Projects
None yet
2 participants
@funkyfuture
Copy link
Member

funkyfuture commented Jul 20, 2015

this is a follow-up of this.

A default-rule would substitute any None-values, empty Mapping and Sequence-instances and numbers equal to zero for a given field with the provided constraint's value while a document is normalized. if the field isn't present at all, it will be added to the document with the constraint's value.

the default-constraint should be processed after coercing.

example:

>>> schema = {'amount': {'default': 1}}
>>> document = {'amount': None}
>>> v.validated(document, schema)
{'amount': 1}
>>> document = {'model': 'The Robots'}
>>> v.normalized(document, schema)
{'model': 'The Robots', 'amount': 1}
@nicolaiarocci

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Jul 22, 2015

Now that we also transform the incoming document, I guess that stuff like this is welcome. Actually, we implemented a default rule in Eve so I know it is useful :) 👍

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Jul 22, 2015

Is there a difference of Eve's rule-design to my proposal?

@nicolaiarocci

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Jul 22, 2015

Yes. Of course Eve does not have or need normalized since input documents are stored to the backend (with defaults added as needed).

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