Edgewall Software

Opened 15 years ago

Last modified 14 years ago

#8751 closed enhancement

refactor transaction handling — at Version 1

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 (last modified by Christian Boos)

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: sandbox/8751-with_transaction

Change History (1)

comment:1 by Christian Boos, 15 years ago

Description: modified (diff)

Patch above applied in r8671.

Note: See TracTickets for help on using tickets.