summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-12-23 13:34:26 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2010-12-23 13:34:26 -0500
commit08ef0e21e06e0f2e90d42c22d2d98846ed62bdec (patch)
tree67b5b179695bced52510fb3002443d6014c2302f
parent015110267e12871ce08c0f3730de0f8488767514 (diff)
downloadsqlalchemy-08ef0e21e06e0f2e90d42c22d2d98846ed62bdec.tar.gz
- slight simplify to state.modified_event()
-rw-r--r--lib/sqlalchemy/orm/attributes.py27
-rw-r--r--lib/sqlalchemy/orm/dynamic.py6
-rw-r--r--lib/sqlalchemy/orm/state.py17
3 files changed, 21 insertions, 29 deletions
diff --git a/lib/sqlalchemy/orm/attributes.py b/lib/sqlalchemy/orm/attributes.py
index bd7e8cf70..7f722aa44 100644
--- a/lib/sqlalchemy/orm/attributes.py
+++ b/lib/sqlalchemy/orm/attributes.py
@@ -438,7 +438,7 @@ class ScalarAttributeImpl(AttributeImpl):
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):
@@ -457,7 +457,7 @@ class ScalarAttributeImpl(AttributeImpl):
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):
@@ -610,7 +610,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
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:
@@ -622,7 +622,7 @@ class ScalarObjectAttributeImpl(ScalarAttributeImpl):
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:
@@ -701,8 +701,7 @@ class CollectionAttributeImpl(AttributeImpl):
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)
@@ -710,8 +709,7 @@ class CollectionAttributeImpl(AttributeImpl):
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:
@@ -720,14 +718,13 @@ class CollectionAttributeImpl(AttributeImpl):
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()
@@ -812,8 +809,9 @@ class CollectionAttributeImpl(AttributeImpl):
# 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
@@ -821,7 +819,6 @@ class CollectionAttributeImpl(AttributeImpl):
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."""
@@ -838,7 +835,7 @@ class CollectionAttributeImpl(AttributeImpl):
# 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
diff --git a/lib/sqlalchemy/orm/dynamic.py b/lib/sqlalchemy/orm/dynamic.py
index 66f7bf739..92bd78a58 100644
--- a/lib/sqlalchemy/orm/dynamic.py
+++ b/lib/sqlalchemy/orm/dynamic.py
@@ -98,10 +98,8 @@ class DynamicAttributeImpl(attributes.AttributeImpl):
state.committed_state[self.key] = CollectionHistory(self, state)
state.modified_event(dict_,
- self,
- False,
- attributes.NEVER_SET,
- passive=attributes.PASSIVE_NO_INITIALIZE)
+ self,
+ attributes.NEVER_SET)
# this is a hack to allow the _base.ComparableEntity fixture
# to work
diff --git a/lib/sqlalchemy/orm/state.py b/lib/sqlalchemy/orm/state.py
index 52cde3a30..6ec4239a3 100644
--- a/lib/sqlalchemy/orm/state.py
+++ b/lib/sqlalchemy/orm/state.py
@@ -312,22 +312,19 @@ class InstanceState(object):
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:
@@ -341,7 +338,7 @@ class InstanceState(object):
self._strong_obj = self.obj()
self.modified = True
-
+
def commit(self, dict_, keys):
"""Commit attributes.