Hello, first of all, I wanna apologize for not contributing for 2 months. Some of you may remember, that in the course of introducing wiki-page renames, which I wanted to revive, the issue of transaction management came up, which currently is done with handle_ta flags. Remy made a suggestion to implement a decorator as_transaction, and I prematurely said I would implement that.
Well, I tried, but I have had not too much python experience, and never made
any more complicated decorators before, and so had some problems, primarily
with scoping.
So I set it aside for the moment being, and then a lot of other stuff came up
for me. Anyway, now I decided to pick it up again, and I have the decorator
implemented now. which is attached in a diff, which also contains the basic
implementation and testing of the rename functionality in the wiki model,
although without dealing with attachments yet (this is just to demonstrate the
decorator).
So, the decorator works fine now, but still has a leftover from the problems I
ran into 2 months ago which drives me crazy:
def as_transaction(env, db):
"""
Decorator for transactions.
Usage:
-- def api_method(p1, p2):
-- @as_transaction(env, db)
-- def implementation_method(p3, p4, db):
-- # implementation
--
-- implementation_method()
"""
def transaction_creator(fn):
db0 = db
def transaction(*args, **kwargs):
db = db0
if not db:
db = env.get_db_cnx()
try:
fn(db = db, *args, **kwargs)
db.commit()
except Exception, e:
db.rollback()
else:
fn(db = db, *args, **kwargs)
return transaction
return transaction_creator
This db0 = db line. For some reason, I just couldn't figure out, over the
course of the defining of the sub-functions, db becomes undefined, but env does
not. The fix is to define a second variable db0 in the middle, that doesn't get
out of scope (or whatever happens there). I really would like to understand
what happens there, and then get rid of this ugly workaround. Did I stumble
over an error in python?
So, I have more time again now, and when this as_transaction thing is accepted,
I would like to pick up the rename again.
Regards
Jan Schukat
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---
as_transaction_rename.diff
Description: Binary data
