Transaction Reference

class pyqldb.transaction.transaction.Transaction(session, read_ahead, transaction_id, executor)[source]

A class representing a QLDB transaction. This is meant for internal use only.

Every transaction is tied to a parent QldbSession, meaning that if the parent session is closed or invalidated, the child transaction is automatically closed and cannot be used. Only one transaction can be active at any given time per parent session, and thus every transaction should call pyqldb.transaction.transaction.Transaction._abort() or pyqldb.transaction.transaction.Transaction._commit() when it is no longer needed, or when a new transaction is desired from the parent session.

An InvalidSessionException indicates that the parent session is dead, and a new transaction cannot be created without a new QldbSession being created from the parent driver.

Any unexpected errors that occur within a transaction should not be retried using the same transaction, as the state of the transaction is now ambiguous.

When an OCC conflict occurs, the transaction is closed and must be handled manually by creating a new transaction and re-executing the desired queries.

Child Cursor objects will be closed when the transaction is aborted or committed.

Parameters
  • session (pyqldb.communication.session_client.SessionClient) – The session object representing a communication channel with QLDB.

  • read_ahead (int) – The number of read-ahead buffers used in retrieving results.

  • transaction_id (str) – The ID of a transaction.

  • executor (concurrent.futures.thread.ThreadPoolExecutor) – The executor to be used by the retrieval thread.

property is_closed

The read-only flag indicating if this transaction has been committed or aborted.

property transaction_id

The read-only ID of this transaction.