Database transaction

I need rollback when occur errors. Is the following code structure right?

try:
    frappe.db.begin()
    -----> DATABASE OPERATIONS <-----
except Exception as e:
    frappe.db.rollback()
else:
    frappe.db.commit()
finally:
    frappe.destroy()
1 Like

@nnylyj, yes this is a right scheme!

EDIT: Note, do you only need this, in async transactions or API methods, but not in controllers