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

ORM: deprecate double underscores in LinkManager contains #5067

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Aug 11, 2021

Fixes #4953

The use of double underscores in the interface of the LinkManager was
recently deprecated for v2.0, however, it unintentionally broke the
__contains__ operator. Legacy code that was using code like:

if 'some__nested__namespace' in node.inputs

which used to work, will now return false, breaking existing code. The
solution is to override the __contains__ operator and check for the
presence of a double underscore in the key. If that is the case, now a
deprecation warning is emitted, but the key is split on the double
underscores and the namespaces are used to fetch the intended nested
dictionary before applying the actual contains check on the leaf node.

@sphuber sphuber force-pushed the fix/4953/deprecate-double-underscore-contains branch from 8766f33 to 6c34e1a Compare August 11, 2021 17:21
@codecov
Copy link

codecov bot commented Aug 11, 2021

Codecov Report

Merging #5067 (4dd16e9) into develop (efd1c3d) will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #5067      +/-   ##
===========================================
+ Coverage    80.38%   80.39%   +0.02%     
===========================================
  Files          529      529              
  Lines        36867    36881      +14     
===========================================
+ Hits         29632    29647      +15     
+ Misses        7235     7234       -1     
Flag Coverage Δ
django 74.89% <100.00%> (+0.01%) ⬆️
sqlalchemy 73.77% <100.00%> (-0.01%) ⬇️

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

Impacted Files Coverage Δ
aiida/orm/utils/managers.py 91.92% <100.00%> (+1.34%) ⬆️
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 efd1c3d...4dd16e9. Read the comment docs.

@ramirezfranciscof
Copy link
Member

Just a small comment: the breaking change was released with v1.6.2 (see "Commits on Apr 26, 2021") so perhaps it would be nice if we could add this to the v1.6.5 release branch you were preparing. Maybe this was your original idea, but since you only mention 2.0 in the OP I just wanted to mention this explicitly.

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.

Great fix! With all paths being tested and all! Only have one comment regarding the clarity of the warning message, but it LGTM.

aiida/orm/utils/managers.py Outdated Show resolved Hide resolved
The use of double underscores in the interface of the `LinkManager` was
recently deprecated for v2.0, however, it unintentionally broke the
`__contains__` operator. Legacy code that was using code like:

    if 'some__nested__namespace' in node.inputs

which used to work, will now return false, breaking existing code. The
solution is to override the `__contains__` operator and check for the
presence of a double underscore in the key. If that is the case, now a
deprecation warning is emitted, but the key is split on the double
underscores and the namespaces are used to fetch the intended nested
dictionary before applying the actual contains check on the leaf node.
@sphuber sphuber force-pushed the fix/4953/deprecate-double-underscore-contains branch from 6c34e1a to 4dd16e9 Compare August 12, 2021 10:20
@sphuber
Copy link
Contributor Author

sphuber commented Aug 12, 2021

Yes, this should also go in the backport release. Once merged, I will cherry-pick it.

@sphuber sphuber merged commit bf80fde into aiidateam:develop Aug 12, 2021
@sphuber sphuber deleted the fix/4953/deprecate-double-underscore-contains branch August 12, 2021 10:41
sphuber added a commit that referenced this pull request Aug 12, 2021
The use of double underscores in the interface of the `LinkManager` was
recently deprecated for v2.0, however, it unintentionally broke the
`__contains__` operator. Legacy code that was using code like:

    if 'some__nested__namespace' in node.inputs

which used to work, will now return false, breaking existing code. The
solution is to override the `__contains__` operator and check for the
presence of a double underscore in the key. If that is the case, now a
deprecation warning is emitted, but the key is split on the double
underscores and the namespaces are used to fetch the intended nested
dictionary before applying the actual contains check on the leaf node.

Cherry-pick: bf80fde
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.

Back incompatible changes introduced in #4625
2 participants