SyncTransactionalSession

class aerospike_sdk.sync.transactional_session.SyncTransactionalSession[source]

Bases: SyncSession

Sync context manager that groups operations into a multi-record transaction.

Subclasses SyncSession, so every session API (query, upsert, insert, batch, …) works unchanged inside with; the underlying async TransactionalSession threads the active Txn onto every policy the builders hand to the PAC — the user never touches a policy.

On clean exit the transaction is committed; if an exception propagates out of the block the transaction is aborted. Explicit commit(), abort(), and rollback() (alias for abort) are also available for manual control.

Example

>>> with client.create_session().begin_transaction() as tx:
...     tx.upsert(accounts.id("A")).bin("balance").set_to(100).execute()
...     tx.upsert(accounts.id("B")).bin("balance").set_to(200).execute()
# Auto-committed on clean exit; auto-aborted on exception.
__init__(async_txn_session, loop_manager)[source]

Wrap async_txn_session; use SyncSession.begin_transaction() instead.

Parameters:

Note

Application code should not construct SyncTransactionalSession directly; call SyncSession.begin_transaction() or Cluster.create_transactional_session() instead.

property txn: Txn

Return the underlying Txn.

Raises:

RuntimeError – If the session has not been entered (no active txn).

Returns:

The active Txn.

property active: bool

True when a transaction has been started and not yet finalized.

Returns:

Whether a transaction is currently active on this session.

commit()[source]

Commit the transaction and return the server-reported status.

Raises:

RuntimeError – If the session has no active transaction.

Return type:

CommitStatus

Returns:

CommitStatus reported by the server.

See also

abort(): Undo the transaction instead of committing.

abort()[source]

Abort the transaction and return the server-reported status.

Raises:

RuntimeError – If the session has no active transaction.

Return type:

AbortStatus

Returns:

AbortStatus reported by the server.

See also

commit(): Persist the transaction instead of aborting. rollback(): Alias for this method.

rollback()[source]

Alias for abort().

Return type:

AbortStatus

Returns:

AbortStatus reported by the server.