summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/session.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-07-13 18:32:42 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-08-07 15:05:00 -0400
commit68879d50faa9e2602e55d5d191647b1cf864e5ab (patch)
treebe9f9e906a3674aa7237ae564eee244931399bae /lib/sqlalchemy/orm/session.py
parent4b4f8fbf25f1a5a76c1579c1a3fd6ffad07c8c66 (diff)
downloadsqlalchemy-68879d50faa9e2602e55d5d191647b1cf864e5ab.tar.gz
Enable multi-level selectin polymorphic loading
Change-Id: Icc742bbeecdb7448ce84caccd63e086af16e81c1 Fixes: #4026
Diffstat (limited to 'lib/sqlalchemy/orm/session.py')
-rw-r--r--lib/sqlalchemy/orm/session.py18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/sqlalchemy/orm/session.py b/lib/sqlalchemy/orm/session.py
index 7c313e635..752f182e5 100644
--- a/lib/sqlalchemy/orm/session.py
+++ b/lib/sqlalchemy/orm/session.py
@@ -1688,6 +1688,7 @@ class Session(_SessionClassMethods):
state.key = instance_key
self.identity_map.replace(state)
+ state._orphaned_outside_of_session = False
statelib.InstanceState._commit_all_states(
((state, state.dict) for state in states),
@@ -1762,6 +1763,7 @@ class Session(_SessionClassMethods):
self.add(instance, _warn=False)
def _save_or_update_state(self, state):
+ state._orphaned_outside_of_session = False
self._save_or_update_impl(state)
mapper = _state_mapper(state)
@@ -2271,11 +2273,17 @@ class Session(_SessionClassMethods):
proc = new.union(dirty).difference(deleted)
for state in proc:
- is_orphan = (
- _state_mapper(state)._is_orphan(state) and state.has_identity)
- _reg = flush_context.register_object(state, isdelete=is_orphan)
- assert _reg, "Failed to add object to the flush context!"
- processed.add(state)
+ is_orphan = _state_mapper(state)._is_orphan(state)
+
+ is_persistent_orphan = is_orphan and state.has_identity
+
+ if is_orphan and not is_persistent_orphan and state._orphaned_outside_of_session:
+ self._expunge_states([state])
+ else:
+ _reg = flush_context.register_object(
+ state, isdelete=is_persistent_orphan)
+ assert _reg, "Failed to add object to the flush context!"
+ processed.add(state)
# put all remaining deletes into the flush context.
if objset: