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

Error on Delta With None Key and Removed Item from List #441

Closed
jasonlenthe opened this issue Dec 11, 2023 · 0 comments · Fixed by #449
Closed

Error on Delta With None Key and Removed Item from List #441

jasonlenthe opened this issue Dec 11, 2023 · 0 comments · Fixed by #449

Comments

@jasonlenthe
Copy link

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

Describe the bug
A TypeError is raised in Delta when using a diff between dicts that have a key None and an item removed from a list:

TypeError: '<' not supported between instances of 'NoneType' and 'str'

Admittedly using None as a key in a dictionary is an unusual edge case, but it is sometimes useful to collect up data with a currently unknown key. I haven't seen anything to suggest that None keys are not supported in deepdiff; please correct me if I'm wrong.

To Reproduce
Steps to reproduce the behavior:

>>> from deepdiff import DeepDiff, Delta
>>> a = { None: [1, 2], 'foo': [1, 2] }
>>> b = { None: [1], 'foo': [1] }
>>> diff = DeepDiff(a, b)
>>> c = a + Delta(diff)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/jlenthe@corp.greenphire.net/deepdiff/venv/lib/python3.8/site-packages/deepdiff/delta.py", line 168, in __add__
    self._do_iterable_item_removed()
  File "/home/jlenthe@corp.greenphire.net/deepdiff/venv/lib/python3.8/site-packages/deepdiff/delta.py", line 580, in _do_iterable_item_removed
    self._do_item_removed(iterable_item_removed)
  File "/home/jlenthe@corp.greenphire.net/deepdiff/venv/lib/python3.8/site-packages/deepdiff/delta.py", line 507, in _do_item_removed
    for path, expected_old_value in sorted(items.items(), key=self._sort_key_for_item_added, reverse=True):
TypeError: '<' not supported between instances of 'NoneType' and 'str'

Expected behavior
Back in version 5.6.0, this case worked without error:

>>> from deepdiff import DeepDiff, Delta
>>> a = { None: [1, 2], 'foo': [1, 2] }
>>> b = { None: [1], 'foo': [1] }
>>> diff = DeepDiff(a, b)
>>> c = a + Delta(diff)
>>> c
{None: [1], 'foo': [1]}

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

  • OS: Ubuntu
  • Version 20.04.6 LTS
  • Python Version 3.8.0
  • DeepDiff Version 6.7.1

Additional context
The error seems to have been introduced with version 5.7.0.

@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.

1 participant