Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"Pre_" methods in Mixins not getting called #353

Open
kevinbosak opened this issue Jun 18, 2021 · 0 comments
Open

"Pre_" methods in Mixins not getting called #353

kevinbosak opened this issue Jun 18, 2021 · 0 comments

Comments

@kevinbosak
Copy link

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant