Error Log doesn't need frappe.db.commit()

I wonder if i can replicate Error Log that doesn’t need frappe.db.commit() to change the value on database

Let me explain
I have API Log, to log all the error for API. But the problem that document have validation frappe.throw to cancel all other transaction. And i want to log the response why it is error.
Yes, true i can use frappe.log_error to know response why it is error, before frappe.throw. And it appeared on frappe.log_error. But i want to save it on doctype API Log so i can assigned to IT person who responsible for it.

Here some example Error Log is always commited, even it save()

Line 1 : Is committed on database
Line 2 : Activity Log is not committed
Line 3. Activity Log is not committed, but Error Log is committed

Error Log table is MyISAM and it doesn’t support transactions so it will always commit immediately. Most if not all other tables are InnoDB so they will respect current transaction and only write the changes on commit.

ref: MyISAM Overview - MariaDB Knowledge Base

Alternate:

  • doc.deferred_insert() this stages document in redis and flushes it every 4 minute to database. Avoids current transaction.

Example: frappe/frappe/core/doctype/access_log/access_log.py at c5caffbfe6ae31e18894dd5364a11000cdfdc0c6 · frappe/frappe · GitHub

3 Likes