Why adding values to a document from console didn’t got validate by the validate or before_save methods?
What I’m trying to say is that I could break the validation and restrictions of adding random values if I used code to insert them.
Is there a way to control that?
Hi Omar,
Can you share a snippet of the code you’re running?
Controller methods like ‘validate()
’ and ‘before_save()
’ are always called (if they exist), when you call the save()
method on a Document.
when you run code in bench console, frappe.db.commit() is not called automatically, to see the effect of data update in validate method call, please run frappe.db.commit() manually.
I noticed something strange!
Here is an example:
doc = frappe.get_doc(…)
doc.save()
Here in this example, the validation will work.
While:
doc = frappe.get_doc(…).save()
Will bypass the validation