Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

DeepDiff not excluding paths when ignore_order is True #174

Closed
bbushnell95 opened this issue Feb 5, 2020 · 4 comments
Closed

DeepDiff not excluding paths when ignore_order is True #174

bbushnell95 opened this issue Feb 5, 2020 · 4 comments
Assignees
Labels

Comments

@bbushnell95
Copy link

bbushnell95 commented Feb 5, 2020

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))
  1. Run the above script
  2. 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'}}}
  1. 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
Copy link

We are seeing the same issue with DeepDiff 4.0.9

@daaain
Copy link

daaain commented Mar 3, 2020

Just ran into this, still happening with 4.2.0

@seperman
Copy link
Owner

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

@seperman seperman added the bug label Mar 10, 2020
@seperman seperman self-assigned this Mar 10, 2020
seperman added a commit that referenced this issue Mar 11, 2020
@seperman
Copy link
Owner

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: eb3973a

Closing this ticket!

netbsd-srcmastr pushed a commit to NetBSD/pkgsrc that referenced this issue May 13, 2020
v4-3-2: Deprecation Warning Enhancement
v4-3-1: Fixing the issue with exclude_path and hash calculations when dictionaries were inside iterables. seperman/deepdiff#174
v4-3-0: adding exclude_obj_callback
v4-2-0: .json property is finally removed. Fix for Py3.10. Dropping support for EOL Python 3.4. Ignoring private keys when calculating hashes. For example init is not a part of hash calculation anymore. Fix for 166 Problem with comparing lists, with an boolean as element.
v4-0-9: Fixing the bug for hashing custom unhashable objects
v4-0-8: Adding ignore_nan_inequality for float('nan')
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants