summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/unitofwork.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/unitofwork.py
parent4b4f8fbf25f1a5a76c1579c1a3fd6ffad07c8c66 (diff)
downloadsqlalchemy-68879d50faa9e2602e55d5d191647b1cf864e5ab.tar.gz
Enable multi-level selectin polymorphic loading
Change-Id: Icc742bbeecdb7448ce84caccd63e086af16e81c1 Fixes: #4026
Diffstat (limited to 'lib/sqlalchemy/orm/unitofwork.py')
-rw-r--r--lib/sqlalchemy/orm/unitofwork.py26
1 files changed, 14 insertions, 12 deletions
diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py
index ee3e2043b..a3bd53637 100644
--- a/lib/sqlalchemy/orm/unitofwork.py
+++ b/lib/sqlalchemy/orm/unitofwork.py
@@ -52,22 +52,24 @@ def track_cascade_events(descriptor, prop):
return
sess = state.session
- if sess:
- prop = state.manager.mapper._props[key]
+ prop = state.manager.mapper._props[key]
- if sess._warn_on_events:
- sess._flush_warning(
- "collection remove"
- if prop.uselist
- else "related attribute delete")
+ if sess and sess._warn_on_events:
+ sess._flush_warning(
+ "collection remove"
+ if prop.uselist
+ else "related attribute delete")
- # expunge pending orphans
- item_state = attributes.instance_state(item)
- if prop._cascade.delete_orphan and \
- item_state in sess._new and \
- prop.mapper._is_orphan(item_state):
+ # expunge pending orphans
+ item_state = attributes.instance_state(item)
+
+ if prop._cascade.delete_orphan and \
+ prop.mapper._is_orphan(item_state):
+ if sess and item_state in sess._new:
sess.expunge(item)
+ else:
+ item_state._orphaned_outside_of_session = True
def set_(state, newvalue, oldvalue, initiator):
# process "save_update" cascade rules for when an instance