refactor transaction handling
|Reported by:||Christian Boos||Owned by:|
Description (last modified by )
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
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:c1f97c626f972010
This ticket will be used to track the progresses of a refactoring branch where we'll generalize this approach: sandbox/8751-with_transaction
Change History (82)
follow-up: 64 comment:62 by , 13 years ago
|Severity:||normal → major|
|Status:||new → closed|