Skip to content

Proposal: Add default-normalization rule #131

Closed
@funkyfuture

Description

@funkyfuture

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}

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions