Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Different behavior when a list has only one item #489

Open
dtphan opened this issue Sep 20, 2024 · 0 comments
Open

Different behavior when a list has only one item #489

dtphan opened this issue Sep 20, 2024 · 0 comments

Comments

@dtphan
Copy link

dtphan commented Sep 20, 2024

Please checkout the F.A.Q page before creating a bug ticket to make sure it is not already addressed.

Describe the bug

To Reproduce

def compare_func(x, y, level=None):
    return x["id"] == y["id"]

# First test case
A = {'array': [{'id': 1, 'x': 'a1'}, {'id': 2, 'x': 'b1'}]}
B = {'array': [{'id': 1, 'x': 'a1'}, {'id': 2, 'x': 'b0'}, {'id': 3, 'x': 'c1'}]}
DeepDiff(A, B, ignore_order=True, report_repetition=True, verbose_level=2, iterable_compare_func=compare_func)
# {'values_changed': {"root['array'][1]['x']": {'new_value': 'b0', 'old_value': 'b1'}}, 
# 'iterable_item_added': {"root['array'][2]": {'id': 3, 'x': 'c1'}}}

# → 1 changed, 1 added: Good and expected

# Second test case
A = {'array': [{'id': 1, 'x': 'a1'}]}
B = {'array': [{'id': 1, 'x': 'a0'}, {'id': 2, 'x': 'b1'}]}
DeepDiff(A, B, ignore_order=True, report_repetition=True, verbose_level=2, iterable_compare_func=compare_func)
# {'iterable_item_added': {"root['array'][0]": {'id': 1, 'x': 'a0'}, "root['array'][1]": {'id': 2, 'x': 'b1'}}, 
# 'iterable_item_removed': {"root['array'][0]": {'id': 1, 'x': 'a1'}}}

# → 2 added, 1 removed: unexpected result
# moreover, the compare_func was not executed at all

# if I remove report_repetition=True, it kind of works but still does not used the specified compare_func
DeepDiff(A, B, ignore_order=True, verbose_level=2, iterable_compare_func=compare_func)
# {'values_changed': {"root['array'][0]": {'new_value': {'id': 1, 'x': 'a0'}, 'old_value': {'id': 1, 'x': 'a1'}}}, 
#  'iterable_item_added': {"root['array'][1]": {'id': 2, 'x': 'b1'}}}

Expected behavior
I expected the second test case to return one 'values_changed' and one 'iterable_item_added', e.g.,

{'values_changed': {"root['array'][0]['x']": {'new_value': 'a0', 'old_value': 'a1'}}, 'iterable_item_added': {"root['array'][1]": {'id': 2, 'x': 'b1'}}}

The compare_func should also be called in the second test case

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

  • OS: Windows
  • Version 11
  • Python Version 3.10.6
  • DeepDiff Version 8.0.1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant