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