On Jul 17, 2013, at 6:42 PM, Jonathan Vanasco <jvana...@gmail.com> wrote:

> the nested transaction / savepoint syntax in sqlalchemy appears to be:
> 
> > session = SessionFactory()
> > session.begin()                 # main tx
> > session.begin_nested()     # outer tx
> > session.begin_nested()     # inner tx
> > session.rollback()             # innter tx
> > session.commit()             # outer tx
> > session.commit()             # main tx
> 
> that's really confusing.  
> 
> thinking of how transactions are supported in postgres , zope/transaction , 
> twisted, and a few other things, I'm left wondering why this pattern was 
> chosen.
> 
> is there any reason why you didn't pursue something like :
> 
> * `session.rollback` and `session.commit` always refer to the 'main' 
> transaction ; `nested_commit()` + `nested_rollback()` are available 

because you can transfer control to some other part of the program that doesn't 
know what kind of transaction has started; it only knows it needs to call 
commit() or can rollback() if something goes wrong.

It's a simple re-entrant calling pattern, not unlike how a threading.RLock 
works, or nesting of context managers, or anything else that nests.  

> 
> * `session.begin_nested()` returns the unique savepoint id ;

why do you need the savepoint id ?   It seems like you're wanting the core API, 
which returns a transactional object specific to that transaction: 
http://docs.sqlalchemy.org/en/rel_0_8/core/connections.html#sqlalchemy.engine.Connection.begin_nested


> passing in that argument to commit/rollback[ `.commit(savepoint)` 
> `.rollback(savepoint)` ] would then release / rollback .  

You can't release/commit savepoints out of order, nor can you release/commit 
them after the outer transaction has been committed or rolled back.  There is 
only one order in which operations can proceed.  So the current API is the 
simplest in that it makes sure you do things this way.

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sqlalchemy+unsubscr...@googlegroups.com.
To post to this group, send email to sqlalchemy@googlegroups.com.
Visit this group at http://groups.google.com/group/sqlalchemy.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to