Just making sure, I am creating an API function with @frappe.whitelist() decorator and within that function there are several database related APIs called (ex: document.save, frappe.new_doc).
If between those API calls, I throw an error via frappe.throw, does previous calls become reverted back. If that so, on the last part of that function should I place a frappe.db.commit() ?
It does implicitly save your object in DB
But it depends on your previous calls if in previous calls you have created some objects that wont get reverted but current transaction will get rolled back
try:
create_item()
so_doc = frappe.new_doc("Sales Order")
so_doc.customer = 'Valen'
# some more properties to this object
so_doc.save()
except Exception,e:
#here you can rollback
frappe.db.rollback() #this will revert only SO current transaction not item object that
we have created