Say I used the threadlocal strategy here. What would the effect of the following nested calls since I use a decorator? Would it detect and use the same connection and the same top level transaction?
engine.begin() <do something> engine.commit() <else> engine.rollback() Thanks for your help in understanding this, Sam. On Jul 15, 7:09 pm, SamDonaldson <[EMAIL PROTECTED]> wrote: > I see the problem here. So what you're saying is that I need some way > of knowing what the parent connection object was to pass through the > decorators and the execute for the nested txn's should happen on the > same connection object. My follow up question is: how do people > usually implement this or do they not use such decorators? Also, > calling engine.connect() based on the docs should still use the > connection pool right? sqlalchemy should be checking out connections > from the pool and not creating new ones right? > > Thanks for you help on this, > > Sam > > On Jul 15, 4:26 pm, jason kirtland <[EMAIL PROTECTED]> wrote: > > > SamDonaldson wrote: > > >[...] > > > I have defined a transaction decorator: > > > def transaction(func): > > > def do(*args, **kw): > > > connection = engine.connect() > > > transaction = connection.begin() > > > try: > > > # create some context here for the connection and pass it > > > through to later execute > > > ret = func(ctx, *args, **kw) > > > transaction.commit() > > > connection.close() > > > return ret > > > except: > > > # rollback for now > > > transaction.rollback() > > > connection.close() > > > return do > > > > [...] > > > The problem occurs when I nest these like this: > > > > @transaction > > > def blah(...) > > > Do a vanilla INSERT into mysql > > > > @transaction > > > def blah2(...) > > > Do some work here and then call blah like this: > > > <work> > > > id = blah(...) <--- hang happens here > > > > My assumption was that sqlalchemy would handle this as nested > > > transactions based on incrementing. How does this affect the > > > connection pool etc..? Any help in understanding this behavior would > > > be appreciated. > > > With engine.connect() you are pulling a new and unrelated db connection > > in each invocation of your transaction decorator. If you want each > > invocation to 'nest' in the same transaction context, you'd need to > > either explicitly pass along the connection or use a threadlocal engine. > > >http://www.sqlalchemy.org/docs/dbengine.html#dbengine_transactions --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "sqlalchemy" 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/sqlalchemy?hl=en -~----------~----~----~----~------~----~------~--~---
