mapper.py raises wrong exception

Issue #528 resolved
Former user created an issue

I made the following fix to help with debugging my own code, and I figured I might as well submit it. When Mapper.init catches an exception raised in calling init on the mapped class, it calls session.expunge(self), but fails to catch further exceptions that might be raised in this call. (In my case, the mapped instance was never attached to the session before an exception was raised in init -- maybe because it inherited from another mapped class and the exception originated in the superclass's constructor? -- leading session.expunge to raise InvalidRequestError: Instance 'XXX' not attached to this Session). My patch just catches exceptions like this and re-raises the original exception as one would expect.

Comments (5)

  1. Mike Bayer repo owner
    • assigned issue to

    need a short unit test added to test/orm/mapper.py MapperTest when this fix is committed.

  2. jek
    • changed status to open
    • removed status
    • marked as major

    This works too well- real internal bugs can hide from unit tests (like changeset:2763). Need some additional tests or tweaks to bring these to light when they happen.

  3. Log in to comment