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

Instantiating a Delta with a flat_dict_list unexpectedly mutates the flat_dict_list #457

Closed
sf-tcalhoun opened this issue Mar 25, 2024 · 1 comment · Fixed by #449
Closed

Comments

@sf-tcalhoun
Copy link
Contributor

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

Describe the bug
We recently discovered some unexpected behaviour which we are considering as a bug. When instantiating a new Delta with a flat_dict_list, which contains indexed list items as being added and removed, we see that the list item path index is getting removed from the flat_dict_list from the perspective of the calling module.

To Reproduce


flat_dict_list = [{'path': ['individualNames', 1],
                                   'value': {'firstName': 'Johnny',
                                             'lastName': 'Doe',
                                             'prefix': '',
                                             'middleName': 'A',
                                             'primaryIndicator': False,
                                             'professionalDesignation': '',
                                             'suffix': 'SR',
                                             'nameIdentifier': '00003'},
                                   'action': 'unordered_iterable_item_added'},
                                  {'path': ['individualNames', 1],
                                   'value': {'firstName': 'John',
                                             'lastName': 'Doe',
                                             'prefix': '',
                                             'middleName': '',
                                             'primaryIndicator': False,
                                             'professionalDesignation': '',
                                             'suffix': 'SR',
                                             'nameIdentifier': '00002'},
                                   'action': 'unordered_iterable_item_removed'}]


        # Note: the list index is provided on the path value...

        # Now use the flat_dict_list to instantiate a new delta...
        delta = Delta(flat_dict_list=flat_dict_list,
                      always_include_values=True, bidirectional=True, raise_errors=True)

        # if the flat_dict_list is (unexpectedly) mutated, it will be missing the list index number on the path value.
        # our flat_dict_list will now look like this:
        mutated_list_missing_indexes_on_path = [{'path': ['individualNames'],
                                         'value': {'firstName': 'Johnny',
                                                   'lastName': 'Doe',
                                                   'prefix': '',
                                                   'middleName': 'A',
                                                   'primaryIndicator': False,
                                                   'professionalDesignation': '',
                                                   'suffix': 'SR',
                                                   'nameIdentifier': '00003'},
                                         'action': 'unordered_iterable_item_added'},
                                        {'path': ['individualNames'],
                                         'value': {'firstName': 'John',
                                                   'lastName': 'Doe',
                                                   'prefix': '',
                                                   'middleName': '',
                                                   'primaryIndicator': False,
                                                   'professionalDesignation': '',
                                                   'suffix': 'SR',
                                                   'nameIdentifier': '00002'},
                                         'action': 'unordered_iterable_item_removed'}]

Expected behavior
A clear and concise description of what you expected to happen.
We expect that the flat_dict_list will be used but not changed/mutated in any way. Think of this as pass by COPY rather than pass by REFERENCE.

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

  • OS: [e.g. Ubuntu] Win10 and/or Linux
  • Version [e.g. 20LTS]
  • Python Version [e.g. 3.9.12] 3.9.12
  • DeepDiff Version [e.g. 5.8.0] 6.7.1 (but using code from dev branch from 3/12/2024)

Additional context
Add any other context about the problem here.
We will submit a Pull Request to fix this issue.

@seperman
Copy link
Owner

seperman commented Apr 5, 2024

Thanks for making the PR @sf-tcalhoun
I will keep you posted. The new release only needs some documentation and will be out.

@seperman seperman mentioned this issue Apr 5, 2024
12 tasks
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

Successfully merging a pull request may close this issue.

2 participants