[email protected] wrote:
> Ok, here the diff.
>
> Have both decorator versions in it now, but use the direct run_as_transaction
> decorator in the tests.
>
>
Ok, thank you and Remy for the heads up, I think I must have missed the
double nesting, so ... right it seems this can be done after all,
perfect :P)
I have a couple of follow-up suggestions:
- We could rename @run_as_transaction to @with_transaction, suggesting
the evolution to using 'with' when moving to 2.5, where this will become
"with transaction(env, db) as db: ..."
- I think we don't need fn(db=...) here, as Remy said we can always
get use anything from the outer scope, so no need to pass any other
arguments besides db
- We could return True/False/None depending on the outcome: True when
committed, False when rollbacked, None if still within a transaction
So this results into something like:
def with_transaction(env, db):
""" ... """
def wrap(fn):
if db:
fn(db)
else:
tmpdb = env.get_db_cnx()
try:
fn(tmpdb)
tmpdb.commit()
return True
except Exception, e:
tmpdb.rollback()
return False
return wrap
-- Christian
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---