I will say that after looking at the SQLAlchemy documentation once again, it does say "For each begin_nested() call, a corresponding rollback() or commit() must be issued." and even from looking at the unit tests in zope.sqlalchemy I cannot tell where the required commit() is issued per savepoint. This may be worth investigating regardless of whether your problem is solved. :-)
http://svn.zope.org/zope.sqlalchemy/trunk/src/zope/sqlalchemy/ On Wed, Nov 16, 2011 at 6:51 AM, Vlad K. <v...@haronmedia.com> wrote: > > Yes it actually works if I use session.flush() instead of > transaction.commit() within the subtransaction. So I guess > transaction.commit() and transaction.abort() close the entire transaction > unlike session.commit() which when matched against session.begin_nested() > releases the savepoint but keeps outer transaction intact. Obviously I > failed to try all combinations before when using savepoint to rollback > would raise an error (because the transaction was finalized with > transaction.commit()). > > Now looking back at all these tests performed and various combinations, it > does all make sense and it was my wrong understanding that I could use > savepoints as "real" subtransactions, ie. commit (to disc) everything > between savepoint and its commit regardless of the "outer" transaction, > although the other way around works: outer transaction can be committed if > "inner" rolled back. > > I still don't know how I can manually release the savepoint using > Transaction, or even if that is necessary at all? Does releasing > savepoint_1 "return" its code back to the "outer" transaction, so that > savepoint_2's failure would not rollback even savepoint_1? > > > So basically this entire issue was caused by my lack of experience with > savepoints and total misunderstanding of how the Transaction package works > as opposed to using SQLA's session directly. > > > .oO V Oo. > > > > On 11/16/2011 09:38 AM, Chris McDonough wrote: > >> On Tue, 2011-11-15 at 11:44 -0600, Michael Merickel wrote: >> >>> It's been hard to follow what has actually been tried, but I just >>> wanted to point some stuff out about zope.sqlalchemy (the code for it >>> is literally 1 small file and shouldn't be talked about with such a >>> scary tone). >>> >>> >>> When doing transaction.savepoint() it returns a savepoint object that >>> calls "session.begin_nested()". and when you call rollback on that >>> savepoint object it calls "session.rollback()". I think that is >>> identical to SQLAlchemy's expected use. For example: >>> >>> >>> sp = transaction.savepoint() # session.begin_nested() >>> try: >>> # do stuff >>> except IntegrityError: >>> sp.rollback() # session.rollback() >>> >>> >>> # do more stuff >>> transaction.commit() # or ideally don't commit and let pyramid_tm do >>> that part for you >>> >> Vlad: it'd be useful to know whether this (savepoint.rollback()) doesn't >> work for you (as opposed to using session.rollback()). >> >> - C >> > > -- > You received this message because you are subscribed to the Google Groups > "pylons-discuss" group. > To post to this group, send email to > pylons-discuss@googlegroups.**com<pylons-discuss@googlegroups.com> > . > To unsubscribe from this group, send email to pylons-discuss+unsubscribe@* > *googlegroups.com <pylons-discuss%2bunsubscr...@googlegroups.com>. > For more options, visit this group at http://groups.google.com/** > group/pylons-discuss?hl=en<http://groups.google.com/group/pylons-discuss?hl=en> > . > > -- Michael -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To post to this group, send email to pylons-discuss@googlegroups.com. To unsubscribe from this group, send email to pylons-discuss+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/pylons-discuss?hl=en.