Transactionable

class Transactionable[source]

Bases: object

Mixin to enable beginning, committing, and aborting transactions (multiple statements). To use Transactionable functionality, subclasses must implement begin(), in_transaction(), commit(), and abort().

begin()[source]

Must be overridden by subclasses. This prepares self to track all changes to self until commit() or abort() is called. If any attributes or data kept by self, this method should probably also call begin() in them.

Has no effect if self is already in a transaction.

Return type

NoReturn

Returns

None

in_transaction()[source]

Query whether self is in a transaction.

Return type

bool

Returns

True if and only if self is currently in a transaction.

commit()[source]

Make all the changes to self since transaction began, and stop tracking changes from now on.

Has no effect if self is not in a transaction.

Return type

NoReturn

Returns

None

abort()[source]

Revert all changes to self since the transaction began, and stop tracking changes from now on.

Has no effect if self is not in a transaction.

Return type

NoReturn

Returns

None

__enter__()[source]
Return type

NoReturn

__exit__(type, *args)[source]

Once the context is ended, if no exception was raised the transaction is committed, otherwise,

Parameters
  • type (Optional[Type]) – Either None or an Exception type, if an Exception was raised in the context.

  • args (Any) – Other possible args provided by the raised Exception

Return type

Optional[Type]

Returns

If there was no exception, or the

exception AbortTransaction[source]

Bases: Exception