mongo
mongo copied to clipboard
Field validation and enforcement on document instantiation.
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!