"nested" = uses SAVEPOINT.  This is the technique the average user wants to 
use.    Background: http://en.wikipedia.org/wiki/Savepoint

"subtransactions" = a code nesting technique.  Is only enabled via a flag so 
that the feature isn't inadvertently used, since it is generally an advanced 
technique.  For usage by frameworks or specific coding patterns that would like 
anonymously nested begin/commit pairs, such as that demonstrated at 
http://www.sqlalchemy.org/docs/core/connections.html#using-transactions .   
Does not create any additional "real" transactions, therefore there is only one 
transaction to be rolled back, which is rolled back when rollback() is called.  
 Pertinent documentation:  begin():  "When a rollback is issued, the 
subtransaction will directly roll back the innermost real transaction".  
rollback():  "This method rolls back the current transaction or nested 
transaction regardless of subtransactions being in effect."




On Nov 1, 2010, at 10:41 AM, Michael Hipp wrote:

> If I do this:
> 
>    item1 = Item()  # a new item
>    self.sess.add(item1)
>    self.sess.begin(subtransactions=True)  # sub transaction
>    item2 = Item()  # another
>    self.sess.add(item2)
>    self.sess.rollback()  # rollback sub trans
>    cnt = self.sess.query(Item).count()  # how many?
> 
> That last line produces an exception:
> InvalidRequestError: This Session's transaction has been rolled back by a 
> nested rollback() call.  To begin a new transaction, issue Session.rollback() 
> first.
> 
> This is not what I expected based on this explanation:
> http://www.sqlalchemy.org/docs/orm/session.html#sqlalchemy.orm.session.Session.begin
> 
> I'm guessing this means that once a rollback is issued on a subtransaction, 
> it is expected that you would immediately travel up the call stack and 
> rollback everything else without touching the db until this is done. Is that 
> correct?
> 
> If so, the documentation linked above could probably be more explicit. In 
> particular, the necessity that the rollback is an all-or-nothing affair.
> 
> I would also enjoy reading some additional explanation of the difference 
> between nested vs. subtransactions and some appropriate use case for each. 
> The docs make it seem as if they are essentially equivalent, but I'm learning 
> this is not the case.
> 
> Thanks,
> Michael
> 
> -- 
> 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.
> 

-- 
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.

Reply via email to