# Transaction

class `trytond.transaction.``Transaction`

This class represents a Tryton transaction that contains thread-local parameters of a database connection. The Transaction instances are context manager that will commit or rollback the database transaction. In the event of an exception the transaction is rolled back, otherwise it is commited.

`Transaction.``database`

  The database.

`Transaction.``readonly`

`Transaction.``connection`

  The database connection as defined by the PEP-0249.

`Transaction.``user`

  The id of the user.

`Transaction.``context`

`Transaction.``create_records`

`Transaction.``delete_records`

`Transaction.``delete`

`Transaction.``timestamp`

`Transaction.``language`

  The language code defines in the context.

`Transaction.``counter`

  Count the number of modification made in this transaction.

`Transaction.``start`(database_name, user[, readonly[, context[, close[, autocommit]]]])

  Start a new transaction and return a context manager. The non-readonly transaction will be committed when exiting the with statement without exception. The other cases will be rollbacked.

`Transaction.``stop`([commit])

  Stop the transaction. If commit is True, the transaction will be committed otherwise it will be rollbacked. The context manager returned by `Transaction.start()` should be used instead of calling this method.

`Transaction.``set_context`(context, **kwargs)

  Update the transaction context and return a context manager. The context will be restored when exiting the with statement.

`Transaction.``reset_context`()

  Clear the transaction context and return a context manager. The context will be restored when exiting the with statement.

`Transaction.``set_user`(user[, set_context])

  Modify the user of the transaction and return a context manager. set_context will put the previous user id in the context to simulate the record rules. The user will be restored when exiting the with statement.

`Transaction.``set_current_transaction`(transaction)

  Add a specific `transaction` on 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]])

  Create a new transaction with the same database, user and context as the original transaction and adds it to the stack of transactions.

`Transaction.``commit`()

  Commit the transaction and all data managers associated.

`Transaction.``rollback`()

  Rollback the transaction and all data managers associated.

`Transaction.``join`(datamanager)

  Register in the transaction a data manager conforming to the Two-Phase Commit protocol. More information on how to implement such data manager is available at the Zope documentation.

  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.