@@ -854,13 +854,15 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
854854 if self ._count_diff () is StopIteration :
855855 return # pragma: no cover. This is already covered for addition.
856856
857+ reference_param1 = i
858+ reference_param2 = j
857859 if y is ListItemRemovedOrAdded : # item removed completely
858860 change_level = level .branch_deeper (
859861 x ,
860862 notpresent ,
861863 child_relationship_class = child_relationship_class ,
862- child_relationship_param = i ,
863- child_relationship_param2 = j ,
864+ child_relationship_param = reference_param1 ,
865+ child_relationship_param2 = reference_param2 ,
864866 )
865867 self ._report_result ('iterable_item_removed' , change_level , local_tree = local_tree )
866868
@@ -869,8 +871,8 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
869871 notpresent ,
870872 y ,
871873 child_relationship_class = child_relationship_class ,
872- child_relationship_param = i ,
873- child_relationship_param2 = j ,
874+ child_relationship_param = reference_param1 ,
875+ child_relationship_param2 = reference_param2 ,
874876 )
875877 self ._report_result ('iterable_item_added' , change_level , local_tree = local_tree )
876878
@@ -881,11 +883,17 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
881883 x ,
882884 y ,
883885 child_relationship_class = child_relationship_class ,
884- child_relationship_param = i ,
885- child_relationship_param2 = j
886+ child_relationship_param = reference_param1 ,
887+ child_relationship_param2 = reference_param2
886888 )
887889 self ._report_result ('iterable_item_moved' , change_level , local_tree = local_tree )
888- continue
890+
891+ if self .iterable_compare_func :
892+ # Intentionally setting j as the first child relationship param in cases of a moved item.
893+ # If the item was moved using an iterable_compare_func then we want to make sure that the index
894+ # is relative to t2.
895+ reference_param1 = j
896+ reference_param2 = i
889897
890898 item_id = id (x )
891899 if parents_ids and item_id in parents_ids :
@@ -897,8 +905,8 @@ def _diff_by_forming_pairs_and_comparing_one_by_one(
897905 x ,
898906 y ,
899907 child_relationship_class = child_relationship_class ,
900- child_relationship_param = i ,
901- child_relationship_param2 = j ,
908+ child_relationship_param = reference_param1 ,
909+ child_relationship_param2 = reference_param2
902910 )
903911 self ._diff (next_level , parents_ids_added , local_tree = local_tree )
904912
0 commit comments