mongoengine icon indicating copy to clipboard operation
mongoengine copied to clipboard

Validation on update/modify

Open shadowtechn opened this issue 6 years ago • 11 comments

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

shadowtechn avatar Dec 31 '18 14:12 shadowtechn

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.

gbroques avatar Dec 31 '18 15:12 gbroques

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.

shadowtechn avatar Dec 31 '18 18:12 shadowtechn

Agreed.

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

gbroques avatar Dec 31 '18 19:12 gbroques

?

shadowtechn avatar Jan 08 '19 11:01 shadowtechn

@gbroques sure, totally :)

erdenezul avatar Jan 23 '19 07:01 erdenezul

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

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

gbroques avatar Jan 23 '19 17:01 gbroques

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.

nr7s avatar Jun 26 '19 10:06 nr7s

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

hellocoldworld avatar Jan 30 '20 14:01 hellocoldworld

Would also really like some updates on this!

burchill avatar Apr 14 '20 20:04 burchill

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?

Adityashaw avatar Jun 17 '20 19:06 Adityashaw

It would be great to have validation on update or modify...

hupanqing avatar Nov 20 '21 02:11 hupanqing