Self.db_set or frappe.set_value

What’s the difference?

@mincerray self.db_set works on specific doctype for example you have the doctype object as doc you use the command to set value in that doctype as (doc.db_set(“price”,50))

frappe.set_value works on any doctype without the need to fetch the object itself so you just use it anytime anywhere and of course on your risk . example frappe.db.set_value(“Sales Invoice”,name,“price”,50). here you have to mention the doctype and the doctype name .

1 Like

also the prefix db_ mean that the operation will bypass python api, im not sure but i think this will write the value directly to the DB without tregering any doctype hooks like before_save etc. also there is no need to call but not sure

I think the frappe.db.set_value does not run the python methods too such as validate()

1 Like