diff options
| author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-10-01 14:00:39 -0400 |
|---|---|---|
| committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-10-01 14:00:39 -0400 |
| commit | 313879d6adedd4fd2a07a4ec30530766f3016885 (patch) | |
| tree | d4188aa5665712ead3a97c75737c766f258a9474 /lib/sqlalchemy | |
| parent | 29d54ab69b689c2bc4b9be8273f4c0a96e37153f (diff) | |
| download | sqlalchemy-313879d6adedd4fd2a07a4ec30530766f3016885.tar.gz | |
Add test and retroactive changelog for issue 4040
Fixes: #4040
Change-Id: I707c1cd2708a37102ad8184bec21be35cb6242d7
Diffstat (limited to 'lib/sqlalchemy')
| -rw-r--r-- | lib/sqlalchemy/orm/session.py | 3 | ||||
| -rw-r--r-- | lib/sqlalchemy/orm/unitofwork.py | 4 |
2 files changed, 6 insertions, 1 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py index 2c7fd86d2..6c5553939 100644 --- a/lib/sqlalchemy/orm/session.py +++ b/lib/sqlalchemy/orm/session.py @@ -2316,7 +2316,8 @@ class Session(_SessionClassMethods): is_persistent_orphan = is_orphan and state.has_identity - if is_orphan and not is_persistent_orphan and state._orphaned_outside_of_session: + if is_orphan and not is_persistent_orphan and \ + state._orphaned_outside_of_session: self._expunge_states([state]) else: _reg = flush_context.register_object( diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index 669fed618..ae5cee8d2 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -69,6 +69,10 @@ def track_cascade_events(descriptor, prop): if sess and item_state in sess._new: sess.expunge(item) else: + # the related item may or may not itself be in a + # Session, however the parent for which we are catching + # the event is not in a session, so memoize this on the + # item item_state._orphaned_outside_of_session = True def set_(state, newvalue, oldvalue, initiator): |
