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
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
1 change: 1 addition & 0 deletions src/aiida/orm/nodes/caching.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _get_objects_to_hash(self) -> list[t.Any]:
except (ImportError, AttributeError) as exc:
raise exceptions.HashingError("The node's package version could not be determined") from exc
objects = [
str(self._node.__class__),
version,
{
key: val
Expand Down
8 changes: 8 additions & 0 deletions tests/orm/nodes/test_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -1009,6 +1009,14 @@ def test_uuid_equality_fallback(self):
assert hash(node_a) != hash(node_0)
assert hash(node_b) != hash(node_0)

def test_subclasses_are_distinguished(self):
"""Test that subclasses get different hashes even if they contain the same attributes."""
node_int = Int(5).store()
node_data = Data()
node_data.base.attributes.set_many(node_int.base.attributes.all)
node_data.store()
assert node_int.base.caching.get_hash() != node_data.base.caching.get_hash()


@pytest.mark.usefixtures('aiida_profile_clean')
def test_iter_repo_keys():
Expand Down
Loading