On Sep 20, 2008, at 1:53 PM, Mariano Cortesi wrote:
> Hi, > > I'm having a problem with session rollback. > > I have a block something like: > > def f(): > try: > #do some queries with session > self.session.commit() > except Exception, e: > self.session.rollback() > raise > > the function that calls f() catchs de exception a do another > transactional block... > that is: > try: > # use the session > self.session.commit() > except Exception, e: > self.session.rollback() > > The problem I have is that both block fail with the same error; as > if the first rollback didn't work... > My patch was to add a self.session.remove() aftter the first > rollback, and now the problem is gone. > But it seems it's a hack and not the best solution. well, it seems like f() catches the error and rethrows, then the enclosing function sees the same exception throw. the rollback() works. if you want to "nest" the transaction used by the session, you can have the inner function call begin() (in 0.5 begin(subtransactions=true) ), which allows logical "nesting" of begin/ commit pairs. or you could have every function call begin()/commit() as well, if you set transactional=False (in 0.5 autocommit=True) which essentially means you'd like to do transactions manually. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
