umongo
umongo copied to clipboard
"Pre_" methods in Mixins not getting called
I'm attempting to create a mixin to add "created" and "updated" fields, much like the docs show except these will be required fields. So I've added pre_insert and pre_update methods to the mixin to be sure those fields get set before storing the doc. The fields are getting added to the model fine, but the hooks are not getting called and I'm getting errors due to those required fields not being set.
@instance.register
class TimeMixin(MixinDocument):
created = DateTimeField(required=True)
updated = DateTimeField(required=True)
def pre_insert(self):
self.created = datetime.datetime.utcnow()
self.updated = datetime.datetime.utcnow()
def pre_update(self):
self.updated = datetime.datetime.utcnow()
@instance.register
class MyDoc(Document, TimeMixin):
...
My "MyDoc" class does not have any hooks defined on it.
Is this a bug or am I missing something obvious? I'm using umongo 3.0.0.