TransactionalSession

class aerospike_sdk.aio.transactional_session.TransactionalSession[source]

Bases: Session

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

Subclasses Session, so every session API (query, upsert, insert, batch, …) works unchanged inside async with; builders capture the active Txn via get_current_transaction() and thread it onto every policy they 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

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

Create a transactional session; prefer Session.begin_transaction().

Parameters:
  • client (Client) – Connected Client.

  • behavior (Optional[Behavior]) – Policy bundle for operations started from this session. Defaults to Behavior.DEFAULT when omitted.

Note

Application code should not construct TransactionalSession directly; call Session.begin_transaction() or Client.transaction_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.

async 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.

async 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.

async rollback()[source]

Alias for abort().

Return type:

AbortStatus

Returns:

AbortStatus reported by the server.