feat(minor): add before_commit methods

This commit is contained in:
Rushabh Mehta 2020-12-17 13:12:49 +05:30 committed by Nabin Hait
parent d5a1faebcb
commit c873c36971
2 changed files with 7 additions and 0 deletions

View file

@ -148,6 +148,7 @@ def init(site, sites_path=None, new_site=False):
"new_site": new_site
})
local.rollback_observers = []
local.before_commit = []
local.test_objects = {}
local.site = site

View file

@ -746,6 +746,9 @@ class Database(object):
def commit(self):
"""Commit current transaction. Calls SQL `COMMIT`."""
for method in frappe.local.before_commit:
frappe.call(method[0], *(method[1] or []), **(method[2] or {}))
self.sql("commit")
frappe.local.rollback_observers = []
@ -753,6 +756,9 @@ class Database(object):
enqueue_jobs_after_commit()
flush_local_link_count()
def add_before_commit(self, method, args=None, kwargs=None):
frappe.local.before_commit.append([method, args, kwargs])
@staticmethod
def flush_realtime_log():
for args in frappe.local.realtime_log: