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

Dict: fix the __eq__ implementation to call super #5159

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions aiida/orm/nodes/data/dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
# For further information please visit http://www.aiida.net #
###########################################################################
"""`Data` sub class to represent a dictionary."""

import copy

from aiida.common import exceptions
Expand Down Expand Up @@ -75,7 +74,7 @@ def __eq__(self, other):
if isinstance(other, dict):
return self.get_dict() == other

return self is other
return super().__eq__(other)

def set_dict(self, dictionary):
""" Replace the current dictionary with another one.
Expand Down
11 changes: 11 additions & 0 deletions tests/orm/data/test_dict.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,14 @@ def test_eq(dictionary):
assert node is node # pylint: disable=comparison-with-itself
assert node == dictionary
assert node != clone

# To test the fallback, where two ``Dict`` nodes are equal if their UUIDs are even if the content is different, we
# create a different node with other content, but artificially give it the same UUID as ``node``. In practice this
# wouldn't happen unless, by accident, two different nodes get the same UUID, the probability of which is minimal.
# Note that we have to set the UUID directly through the database model instance of the backend entity, since it is
# forbidden to change it through the front-end or backend entity instance, for good reasons.
other = Dict(dict={})
other.backend_entity._dbmodel.uuid = node.uuid # pylint: disable=protected-access
assert other.uuid == node.uuid
assert other.dict != node.dict
assert node == other