inveniosoftware / inveniosoftware/dictdiffer
Getting unexpected value in diff when using ignore in add/remove object case
- Dominant language
- Python
- Stars
- 849
- Forks
- 99
- PR merge metrics
- No merged PRs in 30d
Description
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:
```python
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
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))]`
Contributor guide
Assessment
This issue has not been assessed yet.