On Dec 21, 6:27 pm, gizli <mehm...@gmail.com> wrote: > Hi all, > > This is only for people who use the zope extension for SA (http:// > pypi.python.org/pypi/zope.sqlalchemy). Consider the following: > > for task in conn.query(Task): > conn.begin_nested() > try: > conn.delete(task) > conn.commit() > except Exception: > conn.rollback() > conn.commit() > > I noticed that when I use the zope extension and the transaction > manager, I have to code this differently to do the same thing. Most > noticeably, I cannot have a commit inside the for loop anymore (which > closes/discards the save-point). The reason is that transaction.commit > () automatically discards all nested save-points and commits the > entire transaction. So, I need to do something like this: > > for task in conn.query(Task): > conn.begin_nested() > try: > conn.delete(task) > except Exception: > conn.rollback() > transaction.commit() > > Is this acceptable and expected? It just seems wrong to begin nested > transactions this way. conn.commit() is strictly forbidden by the zope > extension. May be the zope extension should allow commits if they are > discarding a savepoint rather than actually doing a commit? Or may be > SA should have a conn.end_nested() rather than commit? Right now, the > terminology is confusing (when I first saw the first piece of code, I > thought the loop was committing the changes at each iteration). > > Could you please shed some light on this situation? > > Thanks.
Take a look at transaction.savepoint(). It looks like it may only support rolling back (not committing) savepoints. http://svn.zope.org/repos/main/zope.sqlalchemy/trunk/src/zope/sqlalchemy/ -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.