MCPcopy
hub / github.com/sqlalchemy/sqlalchemy / after_transaction_create

Method after_transaction_create

lib/sqlalchemy/orm/events.py:1735–1776  ·  view source on GitHub ↗

Execute when a new :class:`.SessionTransaction` is created. This event differs from :meth:`~.SessionEvents.after_begin` in that it occurs for each :class:`.SessionTransaction` overall, as opposed to when transactions are begun on individual database connections. It

(
        self, session: Session, transaction: SessionTransaction
    )

Source from the content-addressed store, hash-verified

1733 """
1734
1735 def after_transaction_create(
1736 self, session: Session, transaction: SessionTransaction
1737 ) -> None:
1738 """Execute when a new :class:`.SessionTransaction` is created.
1739
1740 This event differs from :meth:`~.SessionEvents.after_begin`
1741 in that it occurs for each :class:`.SessionTransaction`
1742 overall, as opposed to when transactions are begun
1743 on individual database connections. It is also invoked
1744 for nested transactions and subtransactions, and is always
1745 matched by a corresponding
1746 :meth:`~.SessionEvents.after_transaction_end` event
1747 (assuming normal operation of the :class:`.Session`).
1748
1749 :param session: the target :class:`.Session`.
1750 :param transaction: the target :class:`.SessionTransaction`.
1751
1752 To detect if this is the outermost
1753 :class:`.SessionTransaction`, as opposed to a "subtransaction" or a
1754 SAVEPOINT, test that the :attr:`.SessionTransaction.parent` attribute
1755 is ``None``::
1756
1757 @event.listens_for(session, "after_transaction_create")
1758 def after_transaction_create(session, transaction):
1759 if transaction.parent is None:
1760 ... # work with top-level transaction
1761
1762 To detect if the :class:`.SessionTransaction` is a SAVEPOINT, use the
1763 :attr:`.SessionTransaction.nested` attribute::
1764
1765 @event.listens_for(session, "after_transaction_create")
1766 def after_transaction_create(session, transaction):
1767 if transaction.nested:
1768 ... # work with SAVEPOINT transaction
1769
1770 .. seealso::
1771
1772 :class:`.SessionTransaction`
1773
1774 :meth:`~.SessionEvents.after_transaction_end`
1775
1776 """
1777
1778 def after_transaction_end(
1779 self, session: Session, transaction: SessionTransaction

Callers 1

__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected