]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
- slight simplify to state.modified_event()
authorMike Bayer <mike_mp@zzzcomputing.com>
Thu, 23 Dec 2010 18:34:26 +0000 (13:34 -0500)
committerMike Bayer <mike_mp@zzzcomputing.com>
Thu, 23 Dec 2010 18:34:26 +0000 (13:34 -0500)
lib/sqlalchemy/orm/attributes.py
lib/sqlalchemy/orm/dynamic.py
lib/sqlalchemy/orm/state.py

index bd7e8cf7066596e8a0f1213e257b77b45c7c23ab..7f722aa444451f4de8c26ebdcd3bb2540651f31b 100644 (file)
@@ -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
index 66f7bf739337cdd6b46c540ad5908ff5f4a732fc..92bd78a5830b5329dcf67a6b4324acaf418e7561 100644 (file)
@@ -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
index 52cde3a30454c7404d1f98893f197c9b17d072bd..6ec4239a353c7d96bb61c8b289a54b5d2e0810c6 100644 (file)
@@ -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.