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.