From 9887fcef7cb70befa73bc3fe5bbd563ca2ac5b78 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Thu, 17 Dec 2020 13:12:49 +0530 Subject: [PATCH] feat(minor): add before_commit methods --- frappe/__init__.py | 1 + frappe/database/database.py | 6 ++++++ 2 files changed, 7 insertions(+) diff --git a/frappe/__init__.py b/frappe/__init__.py index fa7af8b287..4cde8bfe0e 100644 --- a/frappe/__init__.py +++ b/frappe/__init__.py @@ -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 diff --git a/frappe/database/database.py b/frappe/database/database.py index 616dd3c3ec..179206a4af 100644 --- a/frappe/database/database.py +++ b/frappe/database/database.py @@ -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: