Skip to content

TypeError when diffing dict that have bytes keys #472

Open
@jfly

Description

@jfly

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:

  • OS: NixOS
  • Version: nixos-unstable
  • Python Version: 3.10.6
  • DeepDiff Version: multiple, see repros above

Additional context

I ran a git bisect and it appears that this bug was introduced in 230f225.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions