class documentation

class NestedTransaction(Transaction):

View In Hierarchy

Represent a 'nested', or SAVEPOINT transaction.

The .NestedTransaction object is created by calling the _engine.Connection.begin_nested method of _engine.Connection.

When using .NestedTransaction, the semantics of "begin" / "commit" / "rollback" are as follows:

  • the "begin" operation corresponds to the "BEGIN SAVEPOINT" command, where the savepoint is given an explicit name that is part of the state of this object.
  • The .NestedTransaction.commit method corresponds to a "RELEASE SAVEPOINT" operation, using the savepoint identifier associated with this .NestedTransaction.
  • The .NestedTransaction.rollback method corresponds to a "ROLLBACK TO SAVEPOINT" operation, using the savepoint identifier associated with this .NestedTransaction.

The rationale for mimicking the semantics of an outer transaction in terms of savepoints so that code may deal with a "savepoint" transaction and an "outer" transaction in an agnostic way.

See Also

:ref:`session_begin_nested` - ORM version of the SAVEPOINT API.

Method __init__ Undocumented
Method ​_cancel Undocumented
Method ​_close​_impl Undocumented
Method ​_deactivate​_from​_connection Undocumented
Method ​_do​_close Undocumented
Method ​_do​_commit Undocumented
Method ​_do​_deactivate do whatever steps are necessary to set this transaction as "deactive", however leave this transaction object in place as far as the connection's state.
Method ​_do​_rollback Undocumented
Class Variable __slots__ Undocumented
Instance Variable ​_previous​_nested Undocumented
Instance Variable ​_savepoint Undocumented
Instance Variable connection Undocumented
Instance Variable is​_active Undocumented
Property ​_deactivated​_from​_connection True if this transaction is totally deactivated from the connection and therefore can no longer affect its state.

Inherited from Transaction:

Method ​_get​_subject Undocumented
Method ​_rollback​_can​_be​_called indicates the object is in a state that is known to be acceptable for rollback() to be called.
Method ​_transaction​_is​_active Undocumented
Method ​_transaction​_is​_closed Undocumented
Method close Close this .Transaction.
Method commit Commit this .Transaction.
Method rollback Roll back this .Transaction.
Class Variable ​_is​_root Undocumented
Property is​_valid Undocumented

Inherited from TransactionalContext (via Transaction):

Class Method ​_trans​_ctx​_check Undocumented
Method __enter__ Undocumented
Method __exit__ Undocumented
Instance Variable ​_outer​_trans​_ctx Undocumented
Instance Variable ​_trans​_subject Undocumented
def __init__(self, connection):
def _cancel(self):

Undocumented

def _close_impl(self, deactivate_from_connection, warn_already_deactive):

Undocumented

def _deactivate_from_connection(self, warn=True):

Undocumented

def _do_close(self):
def _do_commit(self):
def _do_deactivate(self):

do whatever steps are necessary to set this transaction as "deactive", however leave this transaction object in place as far as the connection's state.

for a "real" transaction this should roll back the transaction and ensure this transaction is no longer a reset agent.

this is used for nesting of marker transactions where the marker can set the "real" transaction as rolled back, however it stays in place.

for 2.0 we hope to remove this nesting feature.

def _do_rollback(self):
__slots__: tuple[str, ...] =
_previous_nested =

Undocumented

_savepoint =

Undocumented

connection =

Undocumented

is_active: bool =

Undocumented

@property
_deactivated_from_connection =
True if this transaction is totally deactivated from the connection and therefore can no longer affect its state.