Skip to content

Commit

Permalink
Allow commit-events to abort by returning False
Browse files Browse the repository at this point in the history
  • Loading branch information
frthjf committed May 24, 2024
1 parent 26939cb commit 299ea20
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/machinable/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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():
Expand Down

0 comments on commit 299ea20

Please sign in to comment.