- changed status to wontfix
Session.clear() doesn't work after IntegrityError
Issue #716
resolved
As a followup to #704, Session.clear() fails after IntegrityError where Session.expunge(obj) works. See attached example.
Comments (1)
-
repo owner - Log in to comment
theres two ways to prevent whats happening from happening.
one is to turn off "cascade" from
Host
toUser
:the other, to explicitly remove
user2
fromhost.users
:When you say
session.expunge(user2)
, user2 is removed. then when you sayUser('joe', host)
,user3
is added to the session, the 'save-update' cascade fires off, sees thathost
is already in the session, and stops.in contrast, when you say
session.clear()
, bothuser2
andhost
are removed. then upon savinguser3
, the 'save-update' cascade hitshost
, keeps on cascading, hitsuser2
, and re-adds it to the session.Therefore either disabling this cascade from
Host
toUser
, or ensuring thatuser2
is removed from all cascading collections, prevents the object from being re-saved to the session.