diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-02-28 11:50:17 -0500 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2018-07-11 14:23:18 -0400 |
commit | 9f09b6ef1807574a1fa9d155d5a80dba455285fd (patch) | |
tree | 19aad069ed1b092496b8dfe42691f4857b4aa55e /lib/sqlalchemy/orm/dependency.py | |
parent | 5fedaa0eb805eb1032ea1f9e39123bbde3629e52 (diff) | |
download | sqlalchemy-9f09b6ef1807574a1fa9d155d5a80dba455285fd.tar.gz |
Don't null FK for collection-removed item with passive_deletes='all'
Fixed issue regarding passive_deletes="all", where the foreign key
attribute of an object is maintained with its value even after the object
is removed from its parent collection. Previously, the unit of work would
set this to NULL even though passive_deletes indicated it should not be
modified.
Change-Id: I5ba98bc388cbdd6323d255b764e02506c2e66896
Fixes: #3844
Diffstat (limited to 'lib/sqlalchemy/orm/dependency.py')
-rw-r--r-- | lib/sqlalchemy/orm/dependency.py | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index 799e633b3..1a68ea9c7 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -434,6 +434,9 @@ class OneToManyDP(DependencyProcessor): def presort_saves(self, uowcommit, states): children_added = uowcommit.memo(('children_added', self), set) + should_null_fks = not self.cascade.delete_orphan and \ + not self.passive_deletes == 'all' + for state in states: pks_changed = self._pks_changed(uowcommit, state) @@ -457,9 +460,10 @@ class OneToManyDP(DependencyProcessor): for child in history.deleted: if not self.cascade.delete_orphan: - uowcommit.register_object(child, isdelete=False, - operation='delete', - prop=self.prop) + if should_null_fks: + uowcommit.register_object(child, isdelete=False, + operation='delete', + prop=self.prop) elif self.hasparent(child) is False: uowcommit.register_object( child, isdelete=True, @@ -528,6 +532,9 @@ class OneToManyDP(DependencyProcessor): # if the old parent wasn't deleted but child was moved. def process_saves(self, uowcommit, states): + should_null_fks = not self.cascade.delete_orphan and \ + not self.passive_deletes == 'all' + for state in states: history = uowcommit.get_attribute_history( state, @@ -541,7 +548,7 @@ class OneToManyDP(DependencyProcessor): self._post_update(child, uowcommit, [state]) for child in history.deleted: - if not self.cascade.delete_orphan and \ + if should_null_fks and not self.cascade.delete_orphan and \ not self.hasparent(child): self._synchronize(state, child, None, True, uowcommit, False) |