On Jan 16, 2009, at 3:18 AM, Saju Pillai wrote:
> > Hi, > > I start a nested transaction and delete a object from the session and > commit. The outer transaction does not see this delete. I tried to > flush but that didn't help. > > session.begin_nested() > session.delete(some_obj) > session.commit() > > session.query....for..some_obj finds it. > > 1. How can I get the changes in the nested transaction to turn up in > the outer transaction without having to commit the outer transaction. you should be getting the results you expect. commit() always issues a flush which in this case should be issuing a DELETE, and then do a RELEASE SAVEPOINT. Take a look at your SQL log output to ensure the expected conversation is occuring. Also note that if you issue session.query(cls).get(x), the get() call specifically will pull from the cache, but in this case the cached object should be expired (since commit() expires everything) - it will then check that the object was not deleted, and in this case would still return None since it was. > 2. I am new to Sqlalchemy and DB based apps in general. The actual > problem I am trying to solve is to write apis that create/update/ > delete objects while in a long running transaction without having to > commit this long running transaction. I am trying to use nested > transactions to see if I can get this to work but if there is a better > way to do this then such pointers will be much appreciated. a long running transaction is going to introduce locking issues and be subject to stale data if your database is subject to concurrent access. Assuming that's all acceptable, there's no need to use savepoints unless you need to be able to rollback within that long running transaction and continue. it depends on what you're trying to do. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
