Hi, I've run into a rather interesting issue, where calling session.rollback() dies. The error I get with SQLA 0.7 is:
<class 'sqlalchemy.exc.InvalidRequestError'>: Can't attach instance <Foo at 0x2acf68808710>; another instance with key (<class 'module.Foo'>, (342,)) is already present in this session. Traceback: sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:672:rollback sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:386:rollback sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:417:_rollback_impl sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:274:_restore_snapshot sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:1620:_update_impl sqlalchemy-rel_0_7/lib/sqlalchemy/orm/session.py:1648:_attach 0.8 gives a slightly different message, but I think it is essentially the same: <type 'exceptions.AssertionError'>: A conflicting state is already present in the identity map for key (<class 'module.Foo'>, (342,)) Traceback: sqlalchemy-default/lib/sqlalchemy/orm/session.py:637:rollback sqlalchemy-default/lib/sqlalchemy/orm/session.py:346:rollback sqlalchemy-default/lib/sqlalchemy/orm/session.py:377:_rollback_impl sqlalchemy-default/lib/sqlalchemy/orm/session.py:233:_restore_snapshot sqlalchemy-default/lib/sqlalchemy/orm/session.py:1578:_update_impl sqlalchemy-default/lib/sqlalchemy/orm/identity.py:115:add What I see when turning on query logging: - The Foo object with primary key 342 is loaded (using a non-primary mapper, if that makes any difference), and then deleted. The session is flushed. - A new object is created (this time using the primary mapper), and during INSERT, SQLite assigns the same primary key to it as the previously deleted object had (I can see that from subsequent SELECT statements referencing the new object; it would be nice if SQLA logged the primary key after an INSERT at debug level) - An application error (unrelated to SQLAlchemy) occurs, which causes rollback() to be called I have a reliable reproducer, but it is the unit test of a large application, so there are lots of possibly unrelated things going on. I've spent two days coming up with a standalone reproducer, but I've failed, that's why I'm sending this mail instead of opening a ticket. Any ideas? Gabor -------------------------------------------------------------------------- NOTICE: Morgan Stanley is not acting as a municipal advisor and the opinions or views contained herein are not intended to be, and do not constitute, advice within the meaning of Section 975 of the Dodd-Frank Wall Street Reform and Consumer Protection Act. If you have received this communication in error, please destroy all electronic and paper copies and notify the sender immediately. Mistransmission is not intended to waive confidentiality or privilege. Morgan Stanley reserves the right, to the extent permitted under applicable law, to monitor electronic communications. This message is subject to terms available at the following link: http://www.morganstanley.com/disclaimers. If you cannot access these links, please notify us by reply message and we will send the contents to you. By messaging with Morgan Stanley you consent to the foregoing. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalchemy@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.