Skip to content

[Bug] Hashing of the number 1 and True produces inconsistent results #150

Closed

Description

@Necrophagos

Description

I have a weird behaviour with ignore_order=True where it sees a diff of two objects that are equal in my optinion

 a = {
    "A List": [
        {
            "Value One": True,
            "Value Two": 24,
            "Value Three": 1
        }
    ],
}

b = {
    "A List": [
        {
            "Value Two": 24,
            "Value Three": 1,
            "Value One": True
        }
    ],
}

from deepdiff import DeepDiff

diff_result = DeepDiff(a, b, ignore_order=True)
print(json.dumps(diff_result, indent=4))

produces

{
    "iterable_item_added": {
        "root['A List'][0]": {
            "Value Two": 24,
            "Value Three": 1,
            "Value One": true
        }
    },
    "iterable_item_removed": {
        "root['A List'][0]": {
            "Value One": true,
            "Value Two": 24,
            "Value Three": 1
        }
    }
}

The only difference is the order of the keys inside the dict.

The values also seem to be relevant. If I only assign numbers inside the dict then deepdiff detects that the objects are the same despite the order.

What do?

Environment

OS: Ubuntu 18.04.2 LTS
Python: Python 3.6.8
deepdiff==4.0.6

Activity

  1. Necrophagos commented on Jul 1, 2019

    @Necrophagos
    Author

    I could kind of narrow it down to a problem where the is a problem with 1 vs True.

    Here are the hasing values

    Value One       92811594354414759544950280658468913931
    True            286821110490183736728180146001011693598
    Value Two       272267926099876093035070951265092329942
    24              10117690639475950056254465627342521112
    Value Three     7710226368046311526055217056590024901
    1               286821110490183736728180146001011693598
    {'Value One': True, 'Value Two': 24, 'Value Three': 1} 338990766718213272754510958482031841423
    
    Value Two       272267926099876093035070951265092329942
    24              10117690639475950056254465627342521112
    Value Three     7710226368046311526055217056590024901
    1               231678797214551245419120414857003063149
    Value One       92811594354414759544950280658468913931
    True            231678797214551245419120414857003063149
    {'Value Two': 24, 'Value Three': 1, 'Value One': True} 151579104084341967660573380786584663019
    

    See how 1 and True get the same hash value. I the first case the hashing for True happens first and then 1 gets the value for that. In the second case the order is different.

  2. changed the title [-]Weird bug with ignore_order=True[/-] [+][Bug] Hashing of the number 1 and True produces inconsistent results[/+] on Jul 1, 2019
  3. Necrophagos commented on Jul 1, 2019

    @Necrophagos
    Author

    This is the issue

    >>> hash(1) == hash(True)
    True
    

    the inconsistent behaviour occur at deephash.py:286 where result = self[obj] fetches the hash if it is already computed but there is no difference between self[1] and self[True]

  4. Necrophagos commented on Jul 1, 2019

    @Necrophagos
    Author
  5. seperman commented on Jul 12, 2019

    @seperman
    Member

    Thanks @Necrophagos! Looking into the issue now.

  6. self-assigned this
    on Jul 12, 2019
  7. added a commit that references this issue on Jul 12, 2019
  8. seperman commented on Jul 15, 2019

    @seperman
    Member

    Closing this ticket since it is resolved.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions