Edgewall Software

Opened 13 years ago

Last modified 12 years ago

#8751 closed enhancement

refactor transaction handling — at Initial Version

Reported by: Christian Boos Owned by:
Priority: normal Milestone: 0.12
Component: general Version: 0.12dev
Severity: major Keywords: with_transaction
Cc: Branch:
Release Notes:
API Changes:
Internal Changes:

Description

Since the Trac 0.9 days, most of the data model methods are taking a db argument defaulting to None, with the convention that if None, the method should commit the transaction itself, otherwise it is just performing a part in the scope of a wider transaction.

Now, the logic above has been implemented explicitly in each method, with the help of flags (e.g. "handle_ta") and explicit calls to commit.

Not only this is verbose, but doing a rollback on failure was often missing.

The context managers and the with syntax introduced in Python 2.5 are ideally suited to handle such situations. As we still have to support Python 2.4, a slightly less optimal approach can nevertheless be work using a decorator.

The following mail has a proof of concept patch which is the result of some design discussion that happened on Trac-dev: googlegroups:trac-dev:http://groups.google.com/group/trac-dev/msg/c1f97c626f972010

This ticket will be used to track the progresses of a refactoring branch where we'll generalize this approach.

Change History (0)

Note: See TracTickets for help on using tickets.