Mongoengine: Validation on update/modify

Created on 31 Dec 2018  路  10Comments  路  Source: MongoEngine/mongoengine

How do I enforce a custom vailidation on update/modify operation? Both clean method and attribute.validate don't work, they work only on save()
Thank you

Most helpful comment

Would also really like some updates on this!

All 10 comments

Looks like your right.

Both modify and update don't call validate and thus clean.

Looks like only save calls validate and clean.

Will using save instead of update / modify work?

Looks like this relates to issue #1287.

By this comment, @lafrech seems to think it's not unreasonable to modify update to support validation and clean.

I think it's a good idea to add validation on these operations.. It doesn't make any sense that you could bypass the db enforcment on update.

Agreed.

@bagerard @erdenezul Would one of you accept a PR for this?

?

@gbroques sure, totally :)

@013ymc Do you want to put up a PR for this?

I can help review it, and @erdenezul can merge.

Any follow up on this? It would be a really interesting addition to the package I had to stop using update because of this. The update method is preferable to update instead of having to edit the Document doc object attributes and calling doc.save() it after. When I need to update multiple objects I'm currently iterating over all docs in a collection when update supported update_many with the multi flag.

Any updates on this? It would be great to have optional validation on update

Would also really like some updates on this!

Looks like your right.
...
Looks like only save calls validate and clean.

Will using save instead of update / modify work?

I am calling save after update. It isn't validating. Am I understanding it wrongly?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

nilay-gpt picture nilay-gpt  路  4Comments

aakashef picture aakashef  路  3Comments

lanfon72 picture lanfon72  路  3Comments

kushalmitruka picture kushalmitruka  路  5Comments

MateuszBelczowski picture MateuszBelczowski  路  4Comments