seperman / deepdiff

DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
http://zepworks.com
Other
2.03k stars 224 forks source link

DeepDiff include_path param doesn't work with list of dictionaries #456

Closed Ilargi12 closed 8 months ago

Ilargi12 commented 8 months ago

Describe the bug When passing value to include_path param it doesn't show diff.

To Reproduce

a = [{'id': 1, 'comment': "First item"}, {'id': 2, 'comment': "Second item"}]
b = [{'id': 1, 'comment': "First item"}, {'id': 3, 'comment': "Third item"}]
print(DeepDiff(a, b, include_paths='comment'))

Result

{}

Expected behavior

{'values_changed': {"root[1]['comment']": {'new_value': 'Third item', 'old_value': 'Second item'}}}

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

Additional context When passing "root[1]['comment']" as a value to include_path it works for the second item but I would want to check comment for every item.

seperman commented 8 months ago

Hi @Ilargi12 This is by design. include_paths requires the full path to the parent object where we ignore any diffs under that parent object. https://zepworks.com/deepdiff/current/exclude_paths.html#include-paths Your full path to comment is root[0]['comment']. What you need is a include_regex_paths parameter, which we don't have yet. PRs are very welcome.