Strange behaviour after IntegrityError

Issue #704 resolved
Former user created an issue

This may be two different bugs, but they are so similar that I'm lumping them together on this ticket. Basically, an IntegrityError seems to leave a Session in an invalid state, causing unexpected errors in later calls. This is bad, because sometimes checking for an IntegrityError is useful.

I've attached two examples using the mapped classes User and Host. In the first, after an IntegrityError on the user table, when a new User is saved to a session and the session is flushed, the session attempts to insert old existing User instead. In the second, after an Integrity error on the host table, saving a new User for an existing host erroneously attempts to re-insert that host.

Comments (5)

  1. Mike Bayer repo owner

    it looks to me like in both cases, the instance which you've save()ed within the try/except fails to insert, but its still in the session (session doesn't do anything besides rollback the transaction). so the next flush fails too. the "invalid state" is something you've set up manually, and it just stays there, until you clear(), expunge(), or modify attributes appropriately. if you set "echo_uow=True" in your session, you can see the in-memory identity of each object being saved.

  2. Log in to comment