I am trying to apply custom validation on a Mongoengine modify operation as seen below:
class Form(Document):
fields = ListField(EmbeddedDocumentField(Field))
def modify(self, *args, **kwargs):
for field in self.fields:
if not [field for field in self.fields if field.type == "email"]:
raise ValidationError("Form must have an email field")
super(Form, self).modify(**kwargs)
def update_form(self, modify_kwargs):
return self.modify(**modify_kwargs)
However when I call update_form, the custom validation does not take the updated data into account in modify. Is there some sort of a pre-hook for doing this type of validation?