MCPcopy Create free account
hub / github.com/sqlalchemy/sqlalchemy / after_transaction_create

Method after_transaction_create

lib/sqlalchemy/orm/events.py:1746–1787  ·  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

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

Callers 1

__init__Method · 0.45

Calls

no outgoing calls

Tested by

no test coverage detected