class documentation

class SessionTransaction(TransactionalContext):

View In Hierarchy

A .Session-level transaction.

.SessionTransaction is produced from the _orm.Session.begin and _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 _orm.SessionTransaction is at: :ref:`unitofwork_transaction`.

Changed in version 1.4: The scoping and API methods to work with the _orm.SessionTransaction object directly have been simplified.

See Also

:ref:`unitofwork_transaction`

.Session.begin

.Session.begin_nested

.Session.rollback

.Session.commit

.Session.in_transaction

.Session.in_nested_transaction

.Session.get_transaction

.Session.get_nested_transaction

Method __init__ Undocumented
Method ​_assert​_active Undocumented
Method ​_begin Undocumented
Method ​_connection​_for​_bind Undocumented
Method ​_get​_subject Undocumented
Method ​_iterate​_self​_and​_parents Undocumented
Method ​_prepare​_impl 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
Method close Undocumented
Method commit Undocumented
Method connection Undocumented
Method prepare Undocumented
Method rollback 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
Instance Variable nested Indicates if this is a nested, or SAVEPOINT, transaction.
Instance Variable session Undocumented
Property ​_is​_transaction​_boundary Undocumented
Property is​_active Undocumented
Property parent The parent .SessionTransaction of this .SessionTransaction.

Inherited from TransactionalContext:

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, session, parent=None, nested=False, autobegin=False):

Undocumented

def _assert_active(self, prepared_ok=False, rollback_ok=False, deactive_ok=False, closed_msg='This transaction is closed'):

Undocumented

def _begin(self, nested=False):

Undocumented

def _connection_for_bind(self, bind, execution_options):

Undocumented

def _get_subject(self):
def _iterate_self_and_parents(self, upto=None):

Undocumented

def _prepare_impl(self):

Undocumented

def _remove_snapshot(self):

Remove the restoration state taken before a transaction began.

Corresponds to a commit.

def _restore_snapshot(self, dirty_only=False):

Restore the restoration state taken before a transaction began.

Corresponds to a rollback.

def _rollback_can_be_called(self):

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.

New in version 1.4.28.
def _take_snapshot(self, autobegin=False):

Undocumented

def _transaction_is_active(self):
def _transaction_is_closed(self):
def close(self, invalidate=False):

Undocumented

def commit(self, _to_root=False):

Undocumented

def connection(self, bindkey, execution_options=None, **kwargs):

Undocumented

def prepare(self):

Undocumented

def rollback(self, _capture_exception=False, _to_root=False):

Undocumented

_rollback_exception =

Undocumented

_connections =

Undocumented

_deleted =

Undocumented

_dirty =

Undocumented

_key_switches =

Undocumented

_new =

Undocumented

_parent =

Undocumented

_previous_nested_transaction =

Undocumented

_state =

Undocumented

nested: bool =

Indicates if this is a nested, or SAVEPOINT, transaction.

When .SessionTransaction.nested is True, it is expected that .SessionTransaction.parent will be True as well.

session =

Undocumented

@property
_is_transaction_boundary =

Undocumented

@property
is_active =

Undocumented

@property
parent =

The parent .SessionTransaction of this .SessionTransaction.

If this attribute is None, indicates this .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" or a "nested" / SAVEPOINT transaction. If the .SessionTransaction.nested attribute is True, then this is a SAVEPOINT, and if False, indicates this a subtransaction.

New in version 1.0.16: - use ._parent for previous versions