class SessionTransaction(_StateChange, TransactionalContext): (source)
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 |
Undocumented |
Property | parent |
The parent :class:`.SessionTransaction` of this :class:`.SessionTransaction`. |
Method | _begin |
Undocumented |
Method | _connection |
Undocumented |
Method | _get |
Undocumented |
Method | _iterate |
Undocumented |
Method | _prepare |
Undocumented |
Method | _raise |
Undocumented |
Method | _remove |
Remove the restoration state taken before a transaction began. |
Method | _restore |
Restore the restoration state taken before a transaction began. |
Method | _rollback |
indicates the object is in a state that is known to be acceptable for rollback() to be called. |
Method | _take |
Undocumented |
Method | _transaction |
Undocumented |
Method | _transaction |
Undocumented |
Class Variable | _rollback |
Undocumented |
Instance Variable | _connections |
Undocumented |
Instance Variable | _deleted |
Undocumented |
Instance Variable | _dirty |
Undocumented |
Instance Variable | _key |
Undocumented |
Instance Variable | _new |
Undocumented |
Instance Variable | _parent |
Undocumented |
Instance Variable | _previous |
Undocumented |
Instance Variable | _state |
Undocumented |
Property | _is |
Undocumented |
Inherited from _StateChange
:
Class Method | declare |
Method decorator declaring valid states. |
Method | _expect |
called within a method that changes states. |
Class Variable | _current |
Undocumented |
Instance Variable | _next |
Undocumented |
Inherited from TransactionalContext
(via _StateChange
):
Method | __enter__ |
Undocumented |
Method | __exit__ |
Undocumented |
Class Variable | __slots__ |
Undocumented |
Class Method | _trans |
Undocumented |
Instance Variable | _outer |
Undocumented |
Instance Variable | _trans |
Undocumented |
Session
, origin: SessionTransactionOrigin
, parent: Optional[ SessionTransaction]
= None):
(source)
¶
Undocumented
def close(self, invalidate:
bool
= False):
(source)
¶
Undocumented
def commit(self, _to_root:
bool
= False):
(source)
¶
Undocumented
def connection(self, bindkey:
Optional[ Mapper[ Any]]
, execution_options: Optional[ _ExecuteOptions]
= None, **kwargs: Any
) -> Connection
:
(source)
¶
Undocumented
def rollback(self, _capture_exception:
bool
= False, _to_root: bool
= False):
(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
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
def _begin(self, nested:
bool
= False) -> SessionTransaction
:
(source)
¶
Undocumented
def _connection_for_bind(self, bind:
_SessionBind
, execution_options: Optional[ _ExecuteOptions]
) -> Connection
:
(source)
¶
Undocumented
Optional[ SessionTransaction]
= None) -> Iterable[ SessionTransaction]
:
(source)
¶
Undocumented
def _prepare_impl(self): (source) ¶
Undocumented
str
, state: _StateChangeState
) -> NoReturn
:
(source)
¶
Undocumented
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