SA 0.8.1: nested session transaction (begin_nested) as a context manager fails to rollback

118 views
Skip to first unread message

Antti Haapala

unread,
Apr 30, 2013, 7:35:05 AM4/30/13
to sqlalche...@googlegroups.com

postresql 9.x, psycopg 2.5, I think begin_nested is broken:

An example:

obj = User(username='a_duplicate_username_that_causes_unique_violation')
with session.begin_nested():
    session.add(obj)
    session.flush()

I get an assertion error thrown in session.py:

    437     def __exit__(self, type, value, traceback):
--> 438         self._assert_active(prepared_ok=True)
    439         if self.session.transaction is None:
    440             return

InvalidRequestError: This Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: (IntegrityError) duplicate key value violates unique constraint

Is there something changed here? I think the assertion should also have rollback_ok=True? (as the following code first tries commit, and then if all else fails, as it would fail here, rollback) or am I going to cause even more problems with that change?

Thanks in advance

Michael Bayer

unread,
Apr 30, 2013, 10:05:05 AM4/30/13
to sqlalche...@googlegroups.com
this is http://www.sqlalchemy.org/trac/ticket/2718, regression from 0.7, fixed in rbbaf1d453789 .   You can get the fix via the 0.8 snapshot download at http://www.sqlalchemy.org/download.html , and I might even release 0.8.2 for this one within the week, this is a pretty major regression.  thanks for reporting it.




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

Reply all
Reply to author
Forward
0 new messages