@@ -162,3 +162,60 @@ def load(self):
162162 source .remove (source .get ("parent" , {"name" : "Test-Parent" }), remove_children = True )
163163 source .sync_to (destination )
164164 assert call_order == ["Test-Child" , "Test-Parent" ]
165+
166+
167+ def test_natural_deletion_order_with_noop_parent ():
168+ """Test whether children are recursed through when natural deletion order is set and the parent has no changes."""
169+ call_order = []
170+
171+ class ChildModel (DiffSyncModel ):
172+ _modelname = "child"
173+ _identifiers = ("name" ,)
174+ _attributes = ("attribute" ,)
175+
176+ name : str
177+ attribute : str
178+
179+ def update (self , attrs ):
180+ call_order .append ("Update on child" )
181+ return super ().update (attrs )
182+
183+ class ParentModel (DiffSyncModel ):
184+ _modelname = "parent"
185+ _identifiers = ("name" ,)
186+ _attributes = ("attribute" ,)
187+ _children = {"child" : "children" }
188+
189+ name : str
190+ attribute : str
191+ children : List [ChildModel ] = []
192+
193+ class Adapter (DiffSync ):
194+ top_level = ["parent" ]
195+
196+ parent = ParentModel
197+ child = ChildModel
198+
199+ def load (self , is_source = False ) -> None :
200+ parent = self .parent (name = "Test Parent" , attribute = "This doesn't change" )
201+ parent .model_flags |= DiffSyncModelFlags .NATURAL_DELETION_ORDER
202+ self .add (parent )
203+ if is_source :
204+ child = self .child (name = "Test Child" , attribute = "Attribute from source" )
205+ child .model_flags |= DiffSyncModelFlags .NATURAL_DELETION_ORDER
206+ parent .add_child (child )
207+ self .add (child )
208+ else :
209+ child = self .child (name = "Test Child" , attribute = "Attribute from destination" )
210+ child .model_flags |= DiffSyncModelFlags .NATURAL_DELETION_ORDER
211+ parent .add_child (child )
212+ self .add (child )
213+
214+ source_adapter = Adapter ()
215+ source_adapter .load (is_source = True )
216+ destination_adapter = Adapter ()
217+ destination_adapter .load ()
218+
219+ source_adapter .sync_to (destination_adapter )
220+
221+ assert "Update on child" in call_order
0 commit comments