Skip to content

Field validation and enforcement on document instantiation. #53

Description

@edengreen

Hi,
I came across your project a few days ago, looking for some alternatives to an in-house mongo-wrapper and schema-definition utility.
I was super impressed with marrow-mongo, and the entire echo-system, and I've been trying to use it in my project.

I'm trying to define a document structure with some required fields, and with type validation on each field. Unfortunately, I was not able to get any of these validations to work out of the box (see ipython snippet).

In [27]: class A(Document):
...: n = Number(required=True, validator=never)
...:

In [28]: A()
Out[28]: A()

In [29]: A(n=1)
Out[29]: A(n=1)

It looks as though the required attribute is completely ignored, and so does the validator attribute (however, I was able to enforce validation by adding the Validated mixin to the Field class, but this will force me to redefine each field type I wish to use).

Looking at the code, I wasn't able to find anywhere where these validations are enforced by default, but I'm probably missing something. I'd appreciate you help.

Thanks!

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    2.enhancementNew ideas or improvements.area:documentIssues relating to the Document dictionary–compatible implementation.area:fieldIssues relating to Field implementations or their mechanics.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions