This actually took me a little bit to spot. I can't give a definitive answer, but I can provide some explanation.
On your line in the try block where you say that "transaction.doom() works if placed here before the query", that's where you give the real clue. Somehow, in your setup, a commit is being done before that query gets executed. Because of that, you are now in a new transaction when the child routine raises its own exception. As you're in a new transaction, you no longer can rollback the DBSession.add(urec) that was done. For this particular issue, I have to strongly recommend contacting the SQLAlchemy group. Somehow, a commit is being done, and I'm not capable (personally) of figuring out why. Since SQLAlchemy is doing the commit, I have to recommend asking them for help debugging why the commit is occurring. On Mon, Sep 6, 2010 at 8:32 PM, ozwyzard <[email protected]> wrote: > Hello, > > I attempted trial and error (and poked around some code), but am not > able to figure out the intended method of doing transactions in a TG 2 > application. > > import transaction > > def parent(): > try: > urec = User(name='test', ...) > DBSession.add(urec) > # transaction.doom() works if placed here before the query > newrec = DBSession.query(User).filter(User.name='test', ... > blah) > child_routine_that_does_dependent_DB_ops() # DB op works but > routine raises an exception for TESTING > except Exception, e: > transaction.doom() # Does not remove the urec record from DB > > What is the correct method for doing transaction rollbacks? Does the > rollback not occur after a successful query? Do I need to modify some > config item? > > (I tried setting DBSession.autoflush = False, > transaction.manager.abort(), DBSession.rollback(), but none of these > work). > > Thanks! > > -- > You received this message because you are subscribed to the Google Groups > "TurboGears" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]<turbogears%[email protected]> > . > For more options, visit this group at > http://groups.google.com/group/turbogears?hl=en. > > -- Michael J. Pedersen My IM IDs: Jabber/[email protected], ICQ/103345809, AIM/pedermj022171 Yahoo/pedermj2002, MSN/[email protected] -- You received this message because you are subscribed to the Google Groups "TurboGears" 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/turbogears?hl=en.

