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

Caching: Include the node's class in objects to hash #6321

Merged
merged 1 commit into from
Mar 18, 2024

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Mar 17, 2024

Fixes #6320

The current implementation did not include the class of the node in the list of objects to include in the hash calculation. This made it possible for two nodes of different types but with the same attributes to have the same hash, as long as one type was a subclass of the other.

Arguably when two nodes have a different type, even if subclasses, their hashes should never be the same. Therefore, the node's class is added to the list returned by NodeCaching._get_objects_to_hash().

The current implementation did not include the class of the node in the
list of objects to include in the hash calculation. This made it
possible for two nodes of different types but with the same attributes
to have the same hash, as long as one type was a subclass of the other.

Arguably when two nodes have a different type, even if subclasses, their
hashes should never be the same. Therefore, the node's class is added to
the list returned by `NodeCaching._get_objects_to_hash()`.
Copy link
Member

@unkcpz unkcpz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @sphuber! This change makes a lot sense.
I realize it may also depend on the coding style, if using composition instead of inheritance, the problem does not manifest. https://realpython.com/inheritance-composition-python/

@sphuber sphuber merged commit 68ce111 into aiidateam:main Mar 18, 2024
19 checks passed
@sphuber sphuber deleted the fix/6320/hash-include-node-class branch March 18, 2024 12:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Caching: node class is not taken into account making subclasses potentially indistinguishable
2 participants