From: Mike Bayer Date: Fri, 9 Apr 2010 20:36:58 +0000 (-0400) Subject: removes some unneeded methods, initial DetectKeySwitch not present unnecessarily X-Git-Tag: rel_0_6_0~33 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=bb791e9e4b5d4e3fe2b9c3baa64185caec6f53d1;p=thirdparty%2Fsqlalchemy%2Fsqlalchemy.git removes some unneeded methods, initial DetectKeySwitch not present unnecessarily --- diff --git a/lib/sqlalchemy/orm/dependency.py b/lib/sqlalchemy/orm/dependency.py index dfcddacaa2..f5ac3fff31 100644 --- a/lib/sqlalchemy/orm/dependency.py +++ b/lib/sqlalchemy/orm/dependency.py @@ -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, diff --git a/lib/sqlalchemy/orm/unitofwork.py b/lib/sqlalchemy/orm/unitofwork.py index c93f8af200..537ab74d6e 100644 --- a/lib/sqlalchemy/orm/unitofwork.py +++ b/lib/sqlalchemy/orm/unitofwork.py @@ -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): diff --git a/test/orm/test_unitofworkv2.py b/test/orm/test_unitofworkv2.py index 728cdfd7bb..201b0ad94e 100644 --- a/test/orm/test_unitofworkv2.py +++ b/test/orm/test_unitofworkv2.py @@ -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),