Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion base_exception/models/base_exception_method.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,8 @@ def detect_exceptions(self):
# line) using the current cursor, which sees records created earlier
# in this same transaction even before they are committed.
main_records = self._get_main_records()
rollback = self._exceptions_rollback()
test_mode = test_mode or not rollback
# Write exceptions in a new transaction to be committed so that we can
# rollback the ongoing one while keeping the exceptions stored
with self.env.registry.cursor() as new_cr:
Expand Down Expand Up @@ -138,12 +140,22 @@ def detect_exceptions(self):
or main_records_new_env._must_raise_exception_after_detection()
):
raise_exception = True
if raise_exception:
if raise_exception and rollback:
raise BaseExceptionError(
json.dumps(self._detect_exception_get_exc_class_values())
)
return all_exception_ids

def _exceptions_rollback(self):
"""Store exceptions in a separate transaction and raise to roll back the
ongoing one. False for the records in context
``base_exception_no_rollback={model: ids}``."""
main_records = self._get_main_records()
allowed = self.env.context.get("base_exception_no_rollback") or {}
return not main_records or not set(main_records.ids) <= set(
allowed.get(main_records._name, ())
)

def _detect_exception_get_exc_class_values(self):
return {
"src_model": self._name,
Expand Down
Loading