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

TypeError when diffing dict that have bytes keys #472

Open
jfly opened this issue Jul 17, 2024 · 1 comment
Open

TypeError when diffing dict that have bytes keys #472

jfly opened this issue Jul 17, 2024 · 1 comment
Labels

Comments

@jfly
Copy link

jfly commented Jul 17, 2024

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.

@seperman
Copy link
Owner

@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

@seperman seperman added the bug label Jul 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants