]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
removes some unneeded methods, initial DetectKeySwitch not present unnecessarily
authorMike Bayer <mike_mp@zzzcomputing.com>
Fri, 9 Apr 2010 20:36:58 +0000 (16:36 -0400)
committerMike Bayer <mike_mp@zzzcomputing.com>
Fri, 9 Apr 2010 20:36:58 +0000 (16:36 -0400)
lib/sqlalchemy/orm/dependency.py
lib/sqlalchemy/orm/unitofwork.py
test/orm/test_unitofworkv2.py

index dfcddacaa215c641879d70ea115da9b9404de2a2..f5ac3fff31c4caa25f5eea678e51c01baed83654 100644 (file)
@@ -691,26 +691,7 @@ class DetectKeySwitch(DependencyProcessor):
         if self.prop._reverse_property:
             return
         
-        if not self.passive_updates:
-            # for non-passive updates, register in the preprocess stage
-            # so that mapper save_obj() gets a hold of changes
-            unitofwork.GetDependentObjects(uow, self, False, False)
-        else:
-            
-            ##### TODO ########
-            # Get this out of here if self.parent.base_mapper isn't in the flush!!!!
-            
-            # for passive updates, register objects in the process stage
-            # so that we avoid ManyToOneDP's registering the object without
-            # the listonly flag in its own preprocess stage (results in UPDATE)
-            # statements being emitted
-            parent_saves = unitofwork.SaveUpdateAll(
-                                                uow, 
-                                                self.parent.base_mapper)
-            after_save = unitofwork.ProcessAll(uow, self, False, False)
-            uow.dependencies.update([
-                (parent_saves, after_save)
-            ])
+        unitofwork.GetDependentObjects(uow, self, False, False)
 
     def _has_flush_activity(self, uow):
         pass
@@ -721,9 +702,27 @@ class DetectKeySwitch(DependencyProcessor):
     def presort_deletes(self, uowcommit, states):
         assert False
 
-    def presort_saves(self, uowcommit, states):
-        assert not self.passive_updates
-        self._process_key_switches(states, uowcommit)
+    def presort_saves(self, uow, states):
+        if self.passive_updates:
+            # for passive updates, register objects in the process stage
+            # so that we avoid ManyToOneDP's registering the object without
+            # the listonly flag in its own preprocess stage (results in UPDATE)
+            # statements being emitted
+            for s in states:
+                if self._pks_changed(uow, s):
+                    parent_saves = unitofwork.SaveUpdateAll(
+                                                    uow, 
+                                                    self.parent.base_mapper)
+                    after_save = unitofwork.ProcessAll(uow, self, False, False)
+                    uow.dependencies.update([
+                        (parent_saves, after_save)
+                    ])
+                    return
+                
+        else:
+            # for non-passive updates, register in the preprocess stage
+            # so that mapper save_obj() gets a hold of changes
+            self._process_key_switches(states, uow)
         
     def process_deletes(self, uowcommit, states):
         assert False
@@ -766,24 +765,10 @@ class DetectKeySwitch(DependencyProcessor):
 class ManyToManyDP(DependencyProcessor):
         
     def per_property_flush_actions(self, uow):
-        if self._check_reverse(uow):
-            unitofwork.GetDependentObjects(uow, self, False, True)
-        else:
-            DependencyProcessor.per_property_flush_actions(self, uow)
-
-    def _has_flush_activity(self, uow):
         if self._check_reverse(uow):
             return
-        else:
-            DependencyProcessor._has_flush_activity(self, uow)
-            
-    def per_state_flush_actions(self, uow, states, isdelete):
-        if self._check_reverse(uow):
-            return
-        else:
-            DependencyProcessor.\
-                    per_state_flush_actions(self, uow, states, isdelete)
-            
+        DependencyProcessor.per_property_flush_actions(self, uow)
+
     def per_property_dependencies(self, uow, parent_saves, 
                                                 child_saves, 
                                                 parent_deletes, 
index c93f8af200ccb1bc72078b90d400992debb8d7f1..537ab74d6ee704afa7854c9c1804c283d165c042 100644 (file)
@@ -224,8 +224,8 @@ class UOWTransaction(object):
         #sort = topological.sort(self.dependencies, postsort_actions)
         #print "--------------"
         #print self.dependencies
-        #print postsort_actions
-        #print "COUNT OF POSTSORT ACTIONS", len(postsort_actions)
+        print postsort_actions
+        print "COUNT OF POSTSORT ACTIONS", len(postsort_actions)
         
         # execute
         if self.cycles:
@@ -357,18 +357,17 @@ class ProcessAll(PropertyRecMixin, PostSortRec):
         uow.deps[self.dependency_processor.parent.base_mapper].add(self.dependency_processor)
         
     def execute(self, uow):
-        states = list(self._elements(uow))
+        states = self._elements(uow)
         if self.delete:
             self.dependency_processor.process_deletes(uow, states)
         else:
             self.dependency_processor.process_saves(uow, states)
 
     def per_state_flush_actions(self, uow):
-        # we let the mappers call this,
-        # so that a ProcessAll which is between two mappers that
-        # are part of a cycle (but the ProcessAll itself is not 
-        # in the cycle), also becomes a per-state processor,
-        # and a dependency between the two states as well
+        # this is handled by SaveUpdateAll and DeleteAll,
+        # since a ProcessAll should unconditionally be pulled
+        # into per-state if either the parent/child mappers
+        # are part of a cycle
         return iter([])
         
 class SaveUpdateAll(PostSortRec):
index 728cdfd7bb6f3c0266228eab6c3604898902ee2d..201b0ad94ebef9b15e415fdaa87ecee7511aecaa 100644 (file)
@@ -214,6 +214,16 @@ class RudimentaryFlushTest(UOWTest):
                 ),
         )
 
+    def test_m2o_flush_size(self):
+        mapper(User, users)
+        mapper(Address, addresses, properties={
+            'user':relationship(User, passive_updates=True)
+        })
+        sess = create_session()
+        u1 = User(name='ed')
+        sess.add(u1)
+        self._assert_uow_size(sess, 2)
+        
     def test_o2m_flush_size(self):
         mapper(User, users, properties={
             'addresses':relationship(Address),