Hello Jan, [email protected] wrote: > Hello, > > ... > > 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() > ... > 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 fact that you assign to the db variable in your local function makes it a local variable. It doesn't matter if that assignment is executed or not, it's just a "compile" time decision, in the same way as a function becomes a generator if there's a yield inside. Other than that, yes, it seems worth to switch to something like that, I'll test the patch. -- 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 -~----------~----~----~----~------~----~------~--~---
