The documentation for SessionTransaction has a short example to show  
how it should be used (http://www.sqlalchemy.org/docs/ 
unitofwork.myt#unitofwork_transaction):


sess = create_session()
trans = sess.create_transaction()
try:
     item1 = sess.query(Item).get(1)
     item2 = sess.query(Item).get(2)
     item1.foo = 'bar'
     item2.bar = 'foo'
except:
     trans.rollback()
     raise
trans.commit()


What happens to the transaction if the commit fails? Is it rolled  
back or is it left hanging in an uncommitted state? I personally have  
the urge to structure it like this:


sess = create_session()
trans = sess.create_transaction()
try:
     item1 = sess.query(Item).get(1)
     item2 = sess.query(Item).get(2)
     item1.foo = 'bar'
     item2.bar = 'foo'
     trans.commit()
except:
     trans.rollback()
     raise


That way the transaction is always rolled back in the event of an  
error, even when the commit fails. In fact, that's the way it's done  
within ComposedSQLEngine.transaction(), although that method is not  
working with SessionTransactions. Is there a difference between the  
two approaches?
Thanks.

~ Daniel

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Sqlalchemy-users mailing list
Sqlalchemy-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlalchemy-users

Reply via email to