Can I use frappe.db.commit frequently?

DOCUMENTATION LINK

Can I use this ORM frequently

frappe.db.commit()

What happens If use this command frequently?

Story:
I used this in my shift_type.py file to process the attendance when I’m using the frappe.db.set_value()
the changes won’t reflect after that I used the frappe.db.commit() it’s working fine.

It’s running in the loop. after that, I tried to restart the project. the MariaDB is not working

Someone, please give me an idea of how to solve the db issue, I’m getting this error

Can’t connect with MySQL server

frappe.db.commit essentially runs “COMMIT” against the current transaction in your DBMS. That, along with the execution of certain hooks to ensure data consistency.

It’s likely that the uncommitted transaction is yet to finish execution, and your MariaDB buffers are consumed by this particular job. You can check the process list through the MariaDB client to confirm the same, and potentially kill queries from there.


It would be best if you strived for reducing the number of queries you’re running in a loop - get it as close to a single lightweight query that doesn’t leave a trail of huge temporary tables. Get the set_value out of the loop by building an equivalent optimized filter set.

On the other hand, you may also just want to commit after processing every 10k records or so - based on your appetite.

1 Like