summaryrefslogtreecommitdiff
path: root/lib/sqlalchemy/orm/attributes.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2014-05-30 01:32:53 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2014-05-30 01:32:53 -0400
commit69dbcdd0ebf8de81643c038276fcc822a7b0bd0b (patch)
treeb6cc4a9e12f8ac04b164068d4df8096475b755e2 /lib/sqlalchemy/orm/attributes.py
parent2c8689fd141c278a7bbc250087e553b76a515bc6 (diff)
downloadsqlalchemy-69dbcdd0ebf8de81643c038276fcc822a7b0bd0b.tar.gz
- Related to :ticket:`3060`, an adjustment has been made to the unit
of work such that loading for related many-to-one objects is slightly more aggressive, in the case of a graph of self-referential objects that are to be deleted; the load of related objects is to help determine the correct order for deletion if passive_deletes is not set. - revert the changes to test_delete_unloaded_m2o, these deletes do in fact need to occur in the order of the two child objects first.
Diffstat (limited to 'lib/sqlalchemy/orm/attributes.py')
-rw-r--r--lib/sqlalchemy/orm/attributes.py45
1 files changed, 28 insertions, 17 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index 306c86e3b..df1f328b7 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -23,8 +23,7 @@ from .base import PASSIVE_NO_RESULT, ATTR_WAS_SET, ATTR_EMPTY, NO_VALUE,\
NEVER_SET, NO_CHANGE, CALLABLES_OK, SQL_OK, RELATED_OBJECT_OK,\
INIT_OK, NON_PERSISTENT_OK, LOAD_AGAINST_COMMITTED, PASSIVE_OFF,\
PASSIVE_RETURN_NEVER_SET, PASSIVE_NO_INITIALIZE, PASSIVE_NO_FETCH,\
- PASSIVE_NO_FETCH_RELATED, PASSIVE_ONLY_PERSISTENT, NO_AUTOFLUSH,\
- _none_tuple
+ PASSIVE_NO_FETCH_RELATED, PASSIVE_ONLY_PERSISTENT, NO_AUTOFLUSH
from .base import state_str, instance_str
@inspection._self_inspects
@@ -536,7 +535,7 @@ class AttributeImpl(object):
def get_history(self, state, dict_, passive=PASSIVE_OFF):
raise NotImplementedError()
- def get_all_pending(self, state, dict_):
+ def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
"""Return a list of tuples of (state, obj)
for all objects in this attribute's current state
+ history.
@@ -748,23 +747,31 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
else:
return History.from_object_attribute(self, state, current)
- def get_all_pending(self, state, dict_):
+ def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
if self.key in dict_:
current = dict_[self.key]
- if current is not None:
- ret = [(instance_state(current), current)]
- else:
- ret = [(None, None)]
+ elif passive & CALLABLES_OK:
+ current = self.get(state, dict_, passive=passive)
+ else:
+ return []
+
+ # can't use __hash__(), can't use __eq__() here
+ if current is not None and \
+ current is not PASSIVE_NO_RESULT and \
+ current is not NEVER_SET:
+ ret = [(instance_state(current), current)]
+ else:
+ ret = [(None, None)]
- if self.key in state.committed_state:
- original = state.committed_state[self.key]
- if original not in (NEVER_SET, PASSIVE_NO_RESULT, None) and \
+ if self.key in state.committed_state:
+ original = state.committed_state[self.key]
+ if original is not None and \
+ original is not PASSIVE_NO_RESULT and \
+ original is not NEVER_SET and \
original is not current:
- ret.append((instance_state(original), original))
- return ret
- else:
- return []
+ ret.append((instance_state(original), original))
+ return ret
def set(self, state, dict_, value, initiator,
passive=PASSIVE_OFF, check_old=None, pop=False):
@@ -863,7 +870,9 @@ class CollectionAttributeImpl(AttributeImpl):
else:
return History.from_collection(self, state, current)
- def get_all_pending(self, state, dict_):
+ def get_all_pending(self, state, dict_, passive=PASSIVE_NO_INITIALIZE):
+ # NOTE: passive is ignored here at the moment
+
if self.key not in dict_:
return []
@@ -1091,7 +1100,9 @@ def backref_listeners(attribute, key, uselist):
def emit_backref_from_scalar_set_event(state, child, oldchild, initiator):
if oldchild is child:
return child
- if oldchild not in _none_tuple:
+ if oldchild is not None and \
+ oldchild is not PASSIVE_NO_RESULT and \
+ oldchild is not NEVER_SET:
# With lazy=None, there's no guarantee that the full collection is
# present when updating via a backref.
old_state, old_dict = instance_state(oldchild),\