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 223 forks source link

DeepDiff not excluding paths when ignore_order is True #174

Closed bbushnell95 closed 4 years ago

bbushnell95 commented 4 years ago

Describe the bug When attempting to do a diff between two lists of dictionaries, if ignore_order is defined as True, and exclude_paths is provided, the exclude_paths appears to not be accounted for.

To Reproduce Steps to reproduce the behavior:

  1. Here is the following code snippet I have been using to reproduce the error:
    
    from deepdiff import DeepDiff

obj1 = {'a': 1, 'b': 'randomString', 'e': "1111"} obj2 = {'c': 1, 'd': 'randomString', 'e': 'Cool'}

obj1a = {'a': 1, 'b': 'randomString', 'e': "2222"} obj2a = {'c': 1, 'd': 'randomString', 'e': 'Cool'}

test1 = [obj1, obj2] test2 = [obj2a, obj1a]

exclude_paths = ["root[0]['e']", "root[1]['e']"]

print(DeepDiff(test1, test2, ignore_order=True, report_repetition=True, verbose_level=2, exclude_paths=exclude_paths))

2. Run the above script
3. Result will show be:

{'iterable_item_added': {'root[1]': {'a': 1, 'b': 'AaPedDefault', 'e': '2222'}}, 'iterable_item_removed': {'root[0]': {'a': 1, 'b': 'AaPedDefault', 'e': '1111'}}}

4. If you change the `e` field of obj1a to be the same as obj1['e'], DeepDiff will return an empty object, as expected.

**Expected behavior**
Output of the above should show no diff, as e should be excluded from the paths.

Expected output:

{}



**OS, DeepDiff version and Python version (please complete the following information):**
 - OS: CentOs7
 - DeepDiff Version:  4.2.0
- Python Version: Python 3.6.5
benediktbrandt commented 4 years ago

We are seeing the same issue with DeepDiff 4.0.9

daaain commented 4 years ago

Just ran into this, still happening with 4.2.0

seperman commented 4 years ago

Hi @bbushnell95 Thanks for reporting the issue. Let me take a look at it.

seperman commented 4 years ago

This issue is resolved. v4.3.1 is released. The exclude_path in your example needs the list index in it though.

An example can be found in the tests: https://github.com/seperman/deepdiff/blob/master/tests/test_diff_text.py#L1612

The underlying issue was in DeepHash and is fixed in this commit: https://github.com/seperman/deepdiff/commit/eb3973af209e1287b486a5398d76097563652053

Closing this ticket!