- exception trytond.transaction.TransactionError#
The base class for transaction error that need to retry the transaction.
Update the extras argument of
start()to restart the transaction without the error.
- class trytond.transaction.Transaction#
Represents a Tryton transaction that contains thread-local parameters of a database connection. The Transaction instances are context manager that commits or rollbacks the database transaction. In the event of an exception the transaction is rolled back, otherwise it is commited.
The id of the user.
The set of warnings already checked.
The monotonic timestamp when the transaction started.
The language code defines in the context.
Count the number of modification made in this transaction.
If the access must be enforced.
- Transaction.start(database_name, user[, readonly[, context[, close[, autocommit, \**extras]]]])#
Start a new transaction and return a context manager. The non-readonly transaction will be committed when exiting the
withstatement without exception. The other cases will be rollbacked.
- Transaction.set_context(context, \**kwargs)#
Update the transaction context and return a context manager. The context is restored when exiting the
Clear the transaction context and return a context manager. The context is restored when exiting the
- Transaction.set_user(user[, set_context])#
Modify the user of the transaction and return a context manager.
set_contextwill put the previous user id in the context to simulate the record rules. The user will be restored when exiting the
TransactionErrorto retry the transaction if the table has not been locked at the start.
Add a specific
transactionon the top of the transaction stack. A transaction is commited or rollbacked only when its last reference is popped from the stack.
- Transaction.new_transaction([autocommit[, readonly, \**extras]])#
Create a new transaction with the same database, user and context as the original transaction and adds it to the stack of transactions.
Commit the transaction and all data managers associated.
Rollback the transaction and all data managers associated.
Register in the transaction a data manager conforming to the Two-Phase Commit protocol.
This method returns the registered datamanager. It could be a different yet equivalent (in term of python equality) datamanager than the one passed to the method.
- Transaction.atexit(func, \*args, \*\*kwargs)#
Register a function to be executed upon normal transaction termination. The function can not use the current transaction because it will be already committed or rollbacked.
When called with a function, it decorates the function to be executed with check of access rights. Otherwise it returns a context manager that check access rights until exiting.
When called with a function, it decorates the function to be executed without check of access rights. Otherwise it returns a context manager that disable check access rights until exiting.
When called with a function, it decorates the function to be executed with active test enabled. Otherwise it returns a context manager that enable active test.