"Document has been modified after you have opened it"

I have a custom script that calls a custom method that updates some hidden fields in the Customer document on load (I have also tried with refresh and validate). Whenever I have this script active, when I try to save the Customer I get the “Error: Document has been modified after you have opened it” message.

I thought about moving the hidden fields to a child table so that the doctype isn’t directly being updated but I don’t know how to use set_value with a child table.

Does anyone know either how to fix this error or update child tables through Python?

set_value for child table will be frappe.model.set_value(Doctype, field name, value)

This doesn’t work, when using frappe.model I get

AttributeError: 'module' object has no attribute 'set_value'

Using three arguments with frappe.db gives an error about it expecting 5 arguments and only receiving 4. Looking at the codebase, set_value always seems to expect a document name which I won’t have.

Resolved by adding update_modified=False to the call.

1 Like

How did you do that?

For other people looking at this post and also wondering how, frappe.db.set_value has an optional boolean parameter named “update_modified”. Please see an example here.