class documentation

A :class:`.Session`-level transaction. :class:`.SessionTransaction` is produced from the :meth:`_orm.Session.begin` and :meth:`_orm.Session.begin_nested` methods. It's largely an internal object that in modern use provides a context manager for session transactions. Documentation on interacting with :class:`_orm.SessionTransaction` is at: :ref:`unitofwork_transaction`. .. versionchanged:: 1.4 The scoping and API methods to work with the :class:`_orm.SessionTransaction` object directly have been simplified. .. seealso:: :ref:`unitofwork_transaction` :meth:`.Session.begin` :meth:`.Session.begin_nested` :meth:`.Session.rollback` :meth:`.Session.commit` :meth:`.Session.in_transaction` :meth:`.Session.in_nested_transaction` :meth:`.Session.get_transaction` :meth:`.Session.get_nested_transaction`

Method __init__ Undocumented
Method close Undocumented
Method commit Undocumented
Method connection Undocumented
Method prepare Undocumented
Method rollback Undocumented
Instance Variable nested Indicates if this is a nested, or SAVEPOINT, transaction.
Instance Variable origin Origin of this :class:`_orm.SessionTransaction`.
Instance Variable session Undocumented
Property is_active Undocumented
Property parent The parent :class:`.SessionTransaction` of this :class:`.SessionTransaction`.
Method _begin Undocumented
Method _connection_for_bind Undocumented
Method _get_subject Undocumented
Method _iterate_self_and_parents Undocumented
Method _prepare_impl Undocumented
Method _raise_for_prerequisite_state Undocumented
Method _remove_snapshot Remove the restoration state taken before a transaction began.
Method _restore_snapshot Restore the restoration state taken before a transaction began.
Method _rollback_can_be_called indicates the object is in a state that is known to be acceptable for rollback() to be called.
Method _take_snapshot Undocumented
Method _transaction_is_active Undocumented
Method _transaction_is_closed Undocumented
Class Variable _rollback_exception Undocumented
Instance Variable _connections Undocumented
Instance Variable _deleted Undocumented
Instance Variable _dirty Undocumented
Instance Variable _key_switches Undocumented
Instance Variable _new Undocumented
Instance Variable _parent Undocumented
Instance Variable _previous_nested_transaction Undocumented
Instance Variable _state Undocumented
Property _is_transaction_boundary Undocumented

Inherited from _StateChange:

Class Method declare_states Method decorator declaring valid states.
Method _expect_state called within a method that changes states.
Class Variable _current_fn Undocumented
Instance Variable _next_state Undocumented

Inherited from TransactionalContext (via _StateChange):

Method __enter__ Undocumented
Method __exit__ Undocumented
Class Variable __slots__ Undocumented
Class Method _trans_ctx_check Undocumented
Instance Variable _outer_trans_ctx Undocumented
Instance Variable _trans_subject Undocumented
def __init__(self, session: Session, origin: SessionTransactionOrigin, parent: Optional[SessionTransaction] = None): (source)

Undocumented

Undocumented

def prepare(self): (source)

Undocumented

Indicates if this is a nested, or SAVEPOINT, transaction. When :attr:`.SessionTransaction.nested` is True, it is expected that :attr:`.SessionTransaction.parent` will be present as well, linking to the enclosing :class:`.SessionTransaction`. .. seealso:: :attr:`.SessionTransaction.origin`

Origin of this :class:`_orm.SessionTransaction`. Refers to a :class:`.SessionTransactionOrigin` instance which is an enumeration indicating the source event that led to constructing this :class:`_orm.SessionTransaction`. .. versionadded:: 2.0

Undocumented

Undocumented

The parent :class:`.SessionTransaction` of this :class:`.SessionTransaction`. If this attribute is ``None``, indicates this :class:`.SessionTransaction` is at the top of the stack, and corresponds to a real "COMMIT"/"ROLLBACK" block. If non-``None``, then this is either a "subtransaction" (an internal marker object used by the flush process) or a "nested" / SAVEPOINT transaction. If the :attr:`.SessionTransaction.nested` attribute is ``True``, then this is a SAVEPOINT, and if ``False``, indicates this a subtransaction. .. versionadded:: 1.0.16 - use ._parent for previous versions

Undocumented

def _iterate_self_and_parents(self, upto: Optional[SessionTransaction] = None) -> Iterable[SessionTransaction]: (source)

Undocumented

def _raise_for_prerequisite_state(self, operation_name: str, state: _StateChangeState) -> NoReturn: (source)
def _remove_snapshot(self): (source)

Remove the restoration state taken before a transaction began. Corresponds to a commit.

def _restore_snapshot(self, dirty_only: bool = False): (source)

Restore the restoration state taken before a transaction began. Corresponds to a rollback.

def _rollback_can_be_called(self) -> bool: (source)

indicates the object is in a state that is known to be acceptable for rollback() to be called. This does not necessarily mean rollback() will succeed or not raise an error, just that there is currently no state detected that indicates rollback() would fail or emit warnings. It also does not mean that there's a transaction in progress, as it is usually safe to call rollback() even if no transaction is present. .. versionadded:: 1.4.28

def _take_snapshot(self): (source)

Undocumented

def _transaction_is_active(self) -> bool: (source)
def _transaction_is_closed(self) -> bool: (source)
_rollback_exception: Optional[BaseException] = (source)

Undocumented

_connections: dict = (source)

Undocumented

_deleted = (source)

Undocumented

Undocumented

_key_switches = (source)

Undocumented

Undocumented

Undocumented

_previous_nested_transaction = (source)

Undocumented

Undocumented

@property
_is_transaction_boundary: bool = (source)

Undocumented