MCPcopy
hub / github.com/django/django / on_commit

Method on_commit

django/db/backends/base/base.py:727–747  ·  view source on GitHub ↗
(self, func, robust=False)

Source from the content-addressed store, hash-verified

725 return self.SchemaEditorClass(self, *args, **kwargs)
726
727 def on_commit(self, func, robust=False):
728 if not callable(func):
729 raise TypeError("on_commit()'s callback must be a callable.")
730 if self.in_atomic_block:
731 # Transaction in progress; save for execution on commit.
732 self.run_on_commit.append((set(self.savepoint_ids), func, robust))
733 elif not self.get_autocommit():
734 raise TransactionManagementError(
735 "on_commit() cannot be used in manual transaction management"
736 )
737 else:
738 # No transaction in progress and in autocommit mode; execute
739 # immediately.
740 if robust:
741 try:
742 func()
743 except Exception as e:
744 name = getattr(func, "__qualname__", func)
745 logger.exception("Error calling %s in on_commit() (%s).", name, e)
746 else:
747 func()
748
749 def run_and_clear_commit_hooks(self):
750 self.validate_no_atomic_block()

Callers 1

on_commitFunction · 0.45

Calls 4

get_autocommitMethod · 0.95
callableFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected