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

Remove the equality operator of ExitCode #3940

Merged
merged 1 commit into from
Apr 17, 2020

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Apr 17, 2020

Fixes #3939

The operator implementation assumed that other would always be an
instance of ExitCode as well and so therefore was guaranteed to
contain the same attributes. However, comparing it to a bare tuple would
also invoke the ExitCode.__eq__ method and would raise and
AttributeError as a result. The desired behavior for the equality
operator is that it returns True for any other tuple of the same length
and content. Since this is exactly what is implemented by the tuple
base type, we do not have to override it at all.

@sphuber sphuber requested a review from greschd April 17, 2020 11:44
@greschd
Copy link
Member

greschd commented Apr 17, 2020

Why do we need to implement our own __eq__ in the first place? By inheriting from the namedtuple, ExitCode already has an __eq__, no?

The difference I can see to the current implementation is that tuples also compare equal to lists (and maybe other containers) with the same content.

@codecov
Copy link

codecov bot commented Apr 17, 2020

Codecov Report

Merging #3940 into develop will decrease coverage by 7.96%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #3940      +/-   ##
===========================================
- Coverage    78.23%   70.27%   -7.97%     
===========================================
  Files          461      461              
  Lines        34075    34073       -2     
===========================================
- Hits         26660    23946    -2714     
- Misses        7415    10127    +2712     
Flag Coverage Δ
#django 70.27% <ø> (-0.01%) ⬇️
#sqlalchemy ?
Impacted Files Coverage Δ
aiida/engine/processes/exit_code.py 68.00% <ø> (-2.38%) ⬇️
aiida/backends/sqlalchemy/utils.py 0.00% <0.00%> (-100.00%) ⬇️
aiida/backends/sqlalchemy/testbase.py 0.00% <0.00%> (-100.00%) ⬇️
aiida/backends/sqlalchemy/models/__init__.py 0.00% <0.00%> (-100.00%) ⬇️
...emy/migrations/versions/e797afa09270_reset_hash.py 0.00% <0.00%> (-100.00%) ⬇️
...migrations/versions/5a49629f0d45_dblink_indices.py 0.00% <0.00%> (-100.00%) ⬇️
...ations/versions/118349c10896_default_link_label.py 0.00% <0.00%> (-100.00%) ⬇️
...ations/versions/61fc0913fae9_remove_node_prefix.py 0.00% <0.00%> (-100.00%) ⬇️
...tions/versions/bf591f31dd12_dbgroup_type_string.py 0.00% <0.00%> (-100.00%) ⬇️
...tions/versions/de2eaf6978b4_simplify_user_model.py 0.00% <0.00%> (-100.00%) ⬇️
... and 79 more

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 c746331...c6ae262. Read the comment docs.

@sphuber
Copy link
Contributor Author

sphuber commented Apr 17, 2020

Why do we need to implement our own __eq__ in the first place? By inheriting from the namedtuple, ExitCode already has an __eq__, no?

The difference I can see to the current implementation is that tuples also compare equal to lists (and maybe other containers) with the same content.

Uhm, good question 😅 I just tried and removed the implementation and the tests I added still pass. That means it does distinguish between type, because the list with the same content does not match (which is what we want I think). So I think you are right and the fix is simply to remove it? Huh

@greschd
Copy link
Member

greschd commented Apr 17, 2020

That means it does distinguish between type, because the list with the same content does not match (which is what we want I think). So I think you are right and the fix is simply to remove it? Huh

Right, not sure what made me believe it didn't distinguish list / tuple 😵

Indeed, simply removing it seems like the easiest fix.

@sphuber sphuber force-pushed the fix/3939/serialization-exit-code branch from 163d0fd to 21127ae Compare April 17, 2020 12:17
@sphuber sphuber changed the title Fix the equality operator of ExitCode Remove the equality operator of ExitCode Apr 17, 2020
serialized = yaml.dump(exit_code)
deserialized = yaml.full_load(serialized)
assert deserialized == exit_code

Copy link
Member

Choose a reason for hiding this comment

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

Maybe we should check that the result is still an ExitCode instance here?

The operator implementation assumed that `other` would always be an
instance of `ExitCode` as well and so therefore was guaranteed to
contain the same attributes. However, comparing it to a bare tuple would
also invoke the `ExitCode.__eq__` method and would raise and
`AttributeError` as a result. The desired behavior for the equality
operator is that it returns True for any other tuple of the same length
and content. Since this is exactly what is implemented by the tuple
base type, we do not have to override it at all.
@sphuber sphuber force-pushed the fix/3939/serialization-exit-code branch from 21127ae to c6ae262 Compare April 17, 2020 12:29
Copy link
Member

@greschd greschd left a comment

Choose a reason for hiding this comment

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

Nice! Since this is a pretty significant bug, are you planning a hotfix release for this?

@sphuber sphuber merged commit e33504c into aiidateam:develop Apr 17, 2020
@sphuber sphuber deleted the fix/3939/serialization-exit-code branch April 17, 2020 13:14
@sphuber
Copy link
Contributor Author

sphuber commented Apr 17, 2020

Nice! Since this is a pretty significant bug, are you planning a hotfix release for this?

We should release it soon I agree, but I think I will hold off a bit longer to see if anything else props up. If nothing is reported over the weekend I will release 1.2.1 on Monday I think. Sound reasonable?

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.

Process serialization will fail if it contains an instance of ExitCode
2 participants