MCPcopy
hub / github.com/django/django / captureOnCommitCallbacks

Method captureOnCommitCallbacks

django/test/testcases.py:1511–1540  ·  view source on GitHub ↗

Context manager to capture transaction.on_commit() callbacks.

(cls, *, using=DEFAULT_DB_ALIAS, execute=False)

Source from the content-addressed store, hash-verified

1509 @classmethod
1510 @contextmanager
1511 def captureOnCommitCallbacks(cls, *, using=DEFAULT_DB_ALIAS, execute=False):
1512 """Context manager to capture transaction.on_commit() callbacks."""
1513 callbacks = []
1514 start_count = len(connections[using].run_on_commit)
1515 try:
1516 yield callbacks
1517 finally:
1518 while True:
1519 callback_count = len(connections[using].run_on_commit)
1520 for _, callback, robust in connections[using].run_on_commit[
1521 start_count:
1522 ]:
1523 callbacks.append(callback)
1524 if execute:
1525 if robust:
1526 try:
1527 callback()
1528 except Exception as e:
1529 name = getattr(callback, "__qualname__", callback)
1530 logger.exception(
1531 "Error calling %s in on_commit() (%s).",
1532 name,
1533 e,
1534 )
1535 else:
1536 callback()
1537
1538 if callback_count == len(connections[using].run_on_commit):
1539 break
1540 start_count = callback_count
1541
1542
1543class CheckCondition:

Callers 10

test_no_argumentsMethod · 0.80
test_usingMethod · 0.80
test_different_usingMethod · 0.80
test_executeMethod · 0.80
test_pre_callbackMethod · 0.80
test_execute_treeMethod · 0.80
test_execute_robustMethod · 0.80

Calls 2

callbackFunction · 0.85
appendMethod · 0.45

Tested by

no test coverage detected