Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deepdiff with include-paths is changing results, if a not considered path changes #493

Closed
jlaba opened this issue Oct 10, 2024 · 4 comments · Fixed by #499
Closed

deepdiff with include-paths is changing results, if a not considered path changes #493

jlaba opened this issue Oct 10, 2024 · 4 comments · Fixed by #499
Labels

Comments

@jlaba
Copy link

jlaba commented Oct 10, 2024

Comparing some paths of two dicts with deepdiff the results differ, depending on the presence or absence of other "not included" paths (see also Stackoverflow question).

from deepdiff import DeepDiff
DeepDiff(
    {
        'name': 'Testname',
        'code': 'bla',
        'noneCode': 'blu',
    }, {
        'uid': '12345',
        'name': 'Testname',
    },
    include_paths = "root['name']"
) # expected to be {}, but detects a change

DeepDiff(
    {
        'name': 'Testname',
        'code': 'bla',
    }, {
        'uid': '12345',
        'name': 'Testname',
    },
    include_paths = "root['name']"
) # expected to be {} and is {}

OS, DeepDiff version and Python version (please complete the following information):

  • OS: OpenSuSe Leap 15.6 as well as Windows 11
  • Python Version 3.10 (on linux), 3.11 (on windows)
  • DeepDiff Version 8.0.1
@seperman
Copy link
Owner

@jlaba Thanks for reporting the bug.
We should switch our "include_path" logic so it first does the full diff, then it removes any reports that are outside the include_paths.

@seperman seperman added the bug label Oct 24, 2024
@seperman
Copy link
Owner

Also PRs are very welcome in case you have time to fix it!
Thanks

@jlaba
Copy link
Author

jlaba commented Oct 25, 2024

So I'm not an expert in performance, but most likely in larger dicts, it might be good to only walk through the paths, which should be compared to speed up the process. I had a quick check at the code and most likely this line

if self.include_paths and level_path != 'root':

is the issue. My thesis is, that the problem occurs, because I have not included all root elements. I will try to build a test for it, to check whether the thesis is true :-)

@jlaba
Copy link
Author

jlaba commented Oct 25, 2024

So my thesis proofed to be wrong. The problem is, if the number of items in a dict is changing, even if those added or removed items are not in the included path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants