mongo icon indicating copy to clipboard operation
mongo copied to clipboard

Field validation and enforcement on document instantiation.

Open edengreen opened this issue 7 years ago • 0 comments

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!

edengreen avatar Oct 22 '17 07:10 edengreen