seperman / deepdiff

DeepDiff: Deep Difference and search of any Python object/data. DeepHash: Hash of any object based on its contents. Delta: Use deltas to reconstruct objects by adding deltas together.
http://zepworks.com
Other
1.98k stars 217 forks source link

TypeError when diffing dict that have bytes keys #472

Open jfly opened 1 month ago

jfly commented 1 month ago

To Reproduce

I can reproduce this issue with deepdiff >= 6.7.0. For example:

$ pip install deepdiff==6.7.0
$ python. -c 'import deepdiff; from deepdiff import DeepDiff; print(DeepDiff(t1={b"foo": 1}, t2={b"foobar": 1}))'
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/diff.py", line 320, in __init__
    self._diff(root, parents_ids=frozenset({id(t1)}), _original_type=_original_type)
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/diff.py", line 1563, in _diff
    self._diff_dict(level, parents_ids, local_tree=local_tree)
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/diff.py", line 586, in _diff_dict
    self._report_result(item_added_key, change_level, local_tree=local_tree)
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/diff.py", line 364, in _report_result
    if not self._skip_this(level):
           ^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/diff.py", line 465, in _skip_this
    level_path = level.path()
                 ^^^^^^^^^^^^
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/model.py", line 705, in path
    item = next_rel.get_param_repr(force)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/model.py", line 856, in get_param_repr
    return self.stringify_param(force)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/jeremy/src/github.com/seperman/deepdiff/deepdiff/model.py", line 877, in stringify_param
    has_quote = "'" in param
                ^^^^^^^^^^^^
TypeError: a bytes-like object is required, not 'str'

Expected behavior

On older versions of deepdiff, this works fine. For example, with deepdiff 6.6.1:

$ pip install deepdiff==6.6.1
$ python -c 'import deepdiff; from deepdiff import DeepDiff; print(DeepDiff(t1={b"foo": 1}, t2={b"foobar": 1}))'
{'dictionary_item_added': [root['b'foobar'']], 'dictionary_item_removed': [root['b'foo'']]}

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

I promise this is not relevant, but:

Additional context

I ran a git bisect and it appears that this bug was introduced in https://github.com/seperman/deepdiff/commit/230f225735748f8550eee215c4c6e4ac87c4d7b8.

seperman commented 1 month ago

@jfly I didn't know about git bisect. I used to manually do the binary search through the git commits. Cool. Ok, I will have it fixed in our next release. PRs are always very welcome too. Thanks