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

Getting unexpected value in diff when using ignore in add/remove object case #187

Open
mlasevich opened this issue Feb 4, 2025 · 0 comments
Labels

Comments

@mlasevich
Copy link

Package version (if known):

Describe the bug

When ignoring a subkey, the expectation is that it will be ignored in all cases, however that is not reality. If an object is added/removed instead of changed and a subkey within the object is ignored, that subkey is not ignored/included in the diff

Steps to Reproduce

Example code:

from dictdiffer import diff

a=dict(a="a", b=dict(bb="bb", cc="cc"))
b=dict(a="A", b=dict(bb="BB", cc="cc"))
c=dict(a="A", b=None)

a_vs_b = list(diff(a, b, ignore={'b.bb'}))
print(f"a vs b: {a_vs_b}")
assert a_vs_b == [('change', 'a', ('a', 'A'))]

a_vs_c = list(diff(a, c, ignore={'b.bb'}))
print(f"a vs c: {a_vs_c}")
assert a_vs_c == [('change', 'a', ('a', 'A')), ('change', 'b', ({'cc': 'cc'}, None))]

Result:

a vs b: [('change', 'a', ('a', 'A'))]
a vs c: [('change', 'a', ('a', 'A')), ('change', 'b', ({'bb': 'bb', 'cc': 'cc'}, None))]
Traceback (most recent call last):
  File "/src/example.py", line 13, in <module>
    assert a_vs_c == [('change', 'a', ('a', 'A')), ('change', 'b', ({'cc': 'cc'}, None))]
AssertionError


Expected behavior

Expecting the diff list to not include explicitly ignored keys (i.e.

[('change', 'a', ('a', 'A')), ('change', 'b', ({'cc': 'cc'}, None))]

and not

[('change', 'a', ('a', 'A')), ('change', 'b', ({'bb': 'bb', 'cc': 'cc'}, None))]

@mlasevich mlasevich added the bug label Feb 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant