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

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Oct 4, 2021

Fixes the mistake merged in #5142 and this supersedes #5150

The __eq__ method was recently implemented for the Dict data type
but it erroneously did not call through to the super implementation in
case the dictionary content does not match that of other. This caused
the fallback equality implemented on the Node base class, which
ensures that two nodes with the same UUID compare equal, to be missed.

@codecov
Copy link

codecov bot commented Oct 4, 2021

Codecov Report

Merging #5159 (b4d5f23) into develop (83155d2) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5159      +/-   ##
===========================================
+ Coverage    80.92%   80.93%   +0.01%     
===========================================
  Files          536      536              
  Lines        37054    37054              
===========================================
+ Hits         29984    29985       +1     
+ Misses        7070     7069       -1     
Flag Coverage Δ
django 75.78% <100.00%> (ø)
sqlalchemy 74.93% <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/dict.py 87.24% <100.00%> (ø)
aiida/transports/plugins/local.py 81.66% <0.00%> (+0.26%) ⬆️

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 83155d2...b4d5f23. Read the comment docs.

The `__eq__` method was recently implemented for the `Dict` data type
but it erroneously did not call through to the super implementation in
case the dictionary content does not match that of `other`. This caused
the fallback equality implemented on the `Node` base class, which
ensures that two nodes with the same UUID compare equal, to be missed.
Copy link
Member

@ramirezfranciscof ramirezfranciscof left a comment

Choose a reason for hiding this comment

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

This is a weird "Fix" because it doesn't really matter what you fall back to as long as it is guaranteed to be False (you could even do return False directly), right? This is just a logical impossibility because if the other node is not a Dict then it will not be equal to this Dict.

So, yeah, I mean, we can go ahead and merge I just found it a bit quirky 😅

@sphuber
Copy link
Contributor Author

sphuber commented Oct 6, 2021

This is a weird "Fix" because it doesn't really matter what you fall back to as long as it is guaranteed to be False (you could even do return False directly), right? This is just a logical impossibility because if the other node is not a Dict then it will not be equal to this Dict.

So, yeah, I mean, we can go ahead and merge I just found it a bit quirky sweat_smile

I think you may have misread. The first conditional checks that other is a dict (normal Python built-in), not Dict the node type. So if that fails, for the fallthrough, we can still be comparing two Dict nodes. The fix here is that this should compare their UUIDs, which is implemented by the Node sub class and is not present in object what we were calling before this fix.

@sphuber sphuber merged commit 45238eb into aiidateam:develop Oct 6, 2021
@sphuber sphuber deleted the fix/dict-eq branch October 6, 2021 12:18
@ramirezfranciscof
Copy link
Member

I think you may have misread.

Indeed, haha. Sorry, I was trying to get quick review before something else I had to do I should have read more carefully!

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.

2 participants