if self.dispatch.on_remove:
self.fire_remove_event(state, dict_, old, None)
- state.modified_event(dict_, self, False, old)
+ state.modified_event(dict_, self, old)
del dict_[self.key]
def get_history(self, state, dict_, passive=PASSIVE_OFF):
if self.dispatch.on_set:
value = self.fire_replace_event(state, dict_,
value, old, initiator)
- state.modified_event(dict_, self, False, old)
+ state.modified_event(dict_, self, old)
dict_[self.key] = value
def fire_replace_event(self, state, dict_, value, previous, initiator):
for fn in self.dispatch.on_remove:
fn(state, value, initiator or self)
- state.modified_event(dict_, self, False, value)
+ state.modified_event(dict_, self, value)
def fire_replace_event(self, state, dict_, value, previous, initiator):
if self.trackparent:
for fn in self.dispatch.on_set:
value = fn(state, value, previous, initiator or self)
- state.modified_event(dict_, self, False, previous)
+ state.modified_event(dict_, self, previous)
if self.trackparent:
if value is not None:
for fn in self.dispatch.on_append:
value = fn(state, value, initiator or self)
- state.modified_event(dict_, self, True,
- NEVER_SET, passive=PASSIVE_NO_INITIALIZE)
+ state.modified_event(dict_, self, NEVER_SET, True)
if self.trackparent and value is not None:
self.sethasparent(instance_state(value), True)
return value
def fire_pre_remove_event(self, state, dict_, initiator):
- state.modified_event(dict_, self, True,
- NEVER_SET, passive=PASSIVE_NO_INITIALIZE)
+ state.modified_event(dict_, self, NEVER_SET, True)
def fire_remove_event(self, state, dict_, value, initiator):
if self.trackparent and value is not None:
for fn in self.dispatch.on_remove:
fn(state, value, initiator or self)
- state.modified_event(dict_, self, True,
- NEVER_SET, passive=PASSIVE_NO_INITIALIZE)
+ state.modified_event(dict_, self, NEVER_SET, True)
def delete(self, state, dict_):
if self.key not in dict_:
return
- state.modified_event(dict_, self, True, NEVER_SET)
+ state.modified_event(dict_, self, NEVER_SET, True)
collection = self.get_collection(state, state.dict)
collection.clear_with_event()
# implicitly with in-place operators (foo.collection |= other)
return
- state.modified_event(dict_, self, True, old)
-
+ # place a copy of "old" in state.committed_state
+ state.modified_event(dict_, self, old, True)
+
old_collection = getattr(old, '_sa_adapter')
dict_[self.key] = user_data
collections.bulk_replace(new_values, old_collection, new_collection)
old_collection.unlink(old)
-
def set_committed_value(self, state, dict_, value):
"""Set an attribute value on the given instance and 'commit' it."""
# pending items exist. issue a modified event,
# add/remove new items.
- state.modified_event(dict_, self, True, user_data)
+ state.modified_event(dict_, self, user_data, True)
pending = state.pending.pop(self.key)
added = pending.added_items
def _is_really_none(self):
return self.obj()
-
- def modified_event(self, dict_, attr, should_copy, previous, passive=PASSIVE_OFF):
+
+ def modified_event(self, dict_, attr, previous, collection=False):
if attr.key not in self.committed_state:
- if previous is NEVER_SET:
- if passive:
+ if collection:
+ if previous is NEVER_SET:
if attr.key in dict_:
previous = dict_[attr.key]
- else:
- previous = attr.get(self, dict_)
- if should_copy and previous not in (None, NO_VALUE, NEVER_SET):
- previous = attr.copy(previous)
+ if previous not in (None, NO_VALUE, NEVER_SET):
+ previous = attr.copy(previous)
self.committed_state[attr.key] = previous
-
# the "or not self.modified" is defensive at
# this point. The assertion below is expected
# to be True:
self._strong_obj = self.obj()
self.modified = True
-
+
def commit(self, dict_, keys):
"""Commit attributes.