Skip to content

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

@mlasevich

Description

@mlasevich

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))]

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions