From 299ea20d37effd4845f0cc6620ae54ce17ab6d06 Mon Sep 17 00:00:00 2001 From: Frithjof Gressmann Date: Fri, 24 May 2024 12:28:22 -0500 Subject: [PATCH] Allow commit-events to abort by returning False --- src/machinable/interface.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/machinable/interface.py b/src/machinable/interface.py index 22e02508..43cd3d4b 100644 --- a/src/machinable/interface.py +++ b/src/machinable/interface.py @@ -303,7 +303,9 @@ def commit(self) -> Self: if index.find_by_id(self.uuid) is not None: return self - self.on_before_commit() + if self.on_before_commit() is False: + # allow on_before_commit to abort + return self self.__model__.context = context = self.compute_context() self.__model__.uuid = update_uuid_payload(self.__model__.uuid, context) @@ -312,7 +314,9 @@ def commit(self) -> Self: assert self.config is not None self.__model__.predicate = self.compute_predicate() - self.on_commit() + if self.on_commit() is False: + # allow on_commit to abort + return self # commit to index for k, v in self.__related__.items():