guillotina.transactions¶
- async guillotina.transactions.commit(*, txn=None, warn=True)¶
Commit the current active transaction.
- Parameters:
txn (
Optional[InterfaceClass]) -- transaction to commit- Return type:
None
- async guillotina.transactions.abort(*, txn=None)¶
Abort the current active transaction.
- Parameters:
txn (
Optional[InterfaceClass]) -- transaction to abort- Return type:
None
- guillotina.transactions.get_tm()¶
Return shared transaction manager (from request)
This is used together with "with" syntax for wrapping mutating code into a request owned transaction.
Example:
with get_tm().transaction() as txn: # begin transaction txn # do something # transaction txn commits or raises ConflictError
- Return type:
Optional[InterfaceClass]
- guillotina.transactions.get_transaction()¶
Return the current active transaction.
- Return type:
Optional[InterfaceClass]
- class guillotina.transactions.transaction(*, db=None, tm=None, abort_when_done=False, adopt_parent_txn=False, execute_futures=True, read_only=False)¶
Execute a transaction as async context manager and automatically close connection after done.
>>> async with transaction() as txn: >>> pass
- Parameters:
db -- db to operate transaction on
tm -- transaction manager to retrieve transaction from
abort_when_done -- Abort transaction when done (defaults to false)
adopt_parent_txn -- If this is a sub-transaction, use parent's registered objects
execute_futures -- Execute registered futures with transaction after done (defaults to true)
read_only -- Is this a read_only txn? (default to false)