Ensure that delta replays apply changes to correct t1/t2 based on usage of iterable_compare_func#584
Open
devin13cox wants to merge 1 commit intoqlustered:devfrom
Open
Ensure that delta replays apply changes to correct t1/t2 based on usage of iterable_compare_func#584devin13cox wants to merge 1 commit intoqlustered:devfrom
devin13cox wants to merge 1 commit intoqlustered:devfrom
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Right now when an iterable_compare_func is used, there is a bug that occurs when items both move and change values. What happens is t2 ends up with phantom entries that shouldn't exist in the resulting replay.
The tests below reproduce this at both a surface level and a nested structure.
Part of this issue is the order in which the we apply changes and movements. Currently, to mirror operations in DeepDiff, we apply removals/additions AFTER we apply changes. If we were to flip this (do movement first, then changes), it would actually solve this problem - but this has other implications.
The proposed solutions takes into account that when we go to apply changes, if an iterable_compare_func was used then the original t1 path is actually what we refer to as "new_path" at this point. When iterable_compare_func is not used, then the default path points to the original t1 path. If we always apply changes to the original t1 path, then we don't end up building these phantom entries in t2.
An alternative approach I have explored/tested includes filtering whether or not to apply changes based on if we expect those changes to be overridden by pending movements anyways. This effectively will skip operations that by default are "pointless" (bound to be overridden anyways), and as a side effect it will prevent this bug. Here is some sample code for that (also inside of
deepdiff/delta.py):I wanted to go ahead and propose these two potential fixes, but I am definitely open to alternative approaches if anything else comes to mind, or if these changes have associated risk that I am missing.
Thanks!