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

‼️ BREAKING: Compare Dict nodes by content #5251

Merged
merged 4 commits into from
Dec 7, 2021

Conversation

mbercx
Copy link
Member

@mbercx mbercx commented Dec 7, 2021

Fixes #1917

Currently there is an inconsistency in how the base data type node
instances compare equality. All base types compare based on the content
of the node, whereas Dict instances rely on the UUID fallback
introduced in #4753. After a long discussion started by #1917, it was
finally decided that the best way forward is to make the equality
comparison consitent among the base types (see #5187).

Here we adapt the __eq__ method of the Dict class to compare
equality by content instead of relying on the fallback comparison of
the UUIDs.

Currently there is an inconsistency in how the base data type node
instances compare equality. All base types compare based on the content
of the node, whereas `Dict` instances rely on the UUID fallback
introduced in aiidateam#4753. After a long discussion started by aiidateam#1917, it was
finally decided that the best way forward is to make the equality
comparison consitent among the base types (see aiidateam#5187).

Here we adapt the `__eq__` method of the `Dict` class to compare
equality by content instead of relying on the fallback comparison of
the UUIDs.
@codecov
Copy link

codecov bot commented Dec 7, 2021

Codecov Report

Merging #5251 (4b89c6b) into develop (0682f14) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5251      +/-   ##
===========================================
- Coverage    81.39%   81.38%   -0.00%     
===========================================
  Files          529      529              
  Lines        37009    37002       -7     
===========================================
- Hits         30119    30112       -7     
  Misses        6890     6890              
Flag Coverage Δ
django 76.88% <100.00%> (-<0.01%) ⬇️
sqlalchemy 75.83% <100.00%> (-<0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/orm/nodes/data/base.py 84.62% <ø> (+1.29%) ⬆️
aiida/orm/nodes/data/dict.py 87.24% <100.00%> (ø)
aiida/orm/nodes/data/list.py 91.87% <100.00%> (+0.85%) ⬆️
aiida/engine/daemon/client.py 75.26% <0.00%> (-1.01%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0682f14...4b89c6b. Read the comment docs.

muhrin
muhrin previously approved these changes Dec 7, 2021
Copy link
Contributor

@muhrin muhrin left a comment

Choose a reason for hiding this comment

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

The code changes look fine to me and given that the conclusion of the related discussions was that this breaking change could go ahead I think it's fine to merge.

@mbercx
Copy link
Member Author

mbercx commented Dec 7, 2021

Thanks @muhrin! I'll leave the merging to coding week merge master @chrisjsewell.

Copy link
Contributor

@sphuber sphuber left a comment

Choose a reason for hiding this comment

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

Thanks @mbercx . See comment of removing __ne__. Would do same for other base types that have just plain negation of __eq__. Then I think this OK to merge. Final important thing would be to update the wiki page for v2.0 migration and make a note of this important change.

Comment on lines 78 to 79
def __ne__(self, other):
return not self == other
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should remove this definition of __ne__. By default __ne__ is the negation of __eq__ as stated in the official documentation and so it is recommended not to implement it unless it needs specific functionality

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks @sphuber! Wasn't aware this was the default behaviour, will remove it for List and BaseType as well then.

@mbercx
Copy link
Member Author

mbercx commented Dec 7, 2021

Thanks for the review @sphuber! I've removed the _ne_ operator for the base types and have added a description of this backwards-incompatible change to the v2.0 plugin migration guide:

https://github.com/aiidateam/aiida-core/wiki/AiiDA-2.0-plugin-migration-guide#equality-comparison-of-dict-nodes

@sphuber
Copy link
Contributor

sphuber commented Dec 7, 2021

So can this close #1917? @mbercx ? Any other issues that this PR can close?

@mbercx
Copy link
Member Author

mbercx commented Dec 7, 2021

So can this close #1917? @mbercx ?

Yes, I would say so. It might not be the last time we discuss how to compare node equality, but I think we've all settled on "base types compare content all others compare UUID by default" for now. I'll update the OP.

Any other issues that this PR can close?

Not afaik.

@sphuber sphuber merged commit 21efd99 into aiidateam:develop Dec 7, 2021
@mbercx mbercx deleted the fix/1917/dict-equality branch December 8, 2021 12:51
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.

Distinct instances of the same node do not compare equal
4 participants