Set up an implicit ‘tween’ to do transaction management using the
transactionpackage. The tween will be slotted between the Pyramid request ingress and the Pyramid exception view handler.
For every request it handles, the tween will begin a transaction by calling
request.tm.begin(), and will then call the downstream handler (usually the main Pyramid application request handler) to obtain a response. When attempting to call the downstream handler:
- If an exception is raised by downstream handler while attempting to
obtain a response, the transaction will be rolled back
request.tm.abort()will be called).
- If no exception is raised by the downstream handler, but the
transaction is doomed (
request.tm.doom()has been called), the transaction will be rolled back.
- If the deployment configuration specifies a
tm.commit_vetosetting, and the transaction management tween receives a response from the downstream handler, the commit veto hook will be called. If it returns True, the transaction will be rolled back. If it returns
False, the transaction will be committed.
- If none of the above conditions are true, the transaction will be
- If an exception is raised by downstream handler while attempting to obtain a response, the transaction will be rolled back (
requestis currently being managed by the pyramid_tm tween. If
Falsethen it may be necessary to manage transactions yourself.
When used as a commit veto, the logic in this function will cause the transaction to be aborted if:
X-Tmresponse header with the value
abort(or any value other than
- The response status code starts with
Otherwise the transaction will be allowed to commit.
Create a new
transaction.TransactionManagerin explicit mode.
This is recommended transaction manager and will help to weed out errors caused by code that tweaks the transaction before it has begun or after it has ended.