-
Notifications
You must be signed in to change notification settings - Fork 192
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: Fix deprecation warning being shown for new code types #6407
Conversation
This seems to do the trick. Credits to @giovannipizzi I remember him mentioning an approach like this somewhere sometime ago. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Just one ask for making a comment about how this workaround works.
I tested locally that verdi code create core.code.installed
does not emit warning, while verdi code create core.code
does.
'`isinstance`, use `aiida.orm.nodes.data.code.abstract.AbstractCode`.', | ||
version=3, | ||
) | ||
if getattr(self, '_EMIT_CODE_DEPRECATION_WARNING', True): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for my own understanding; why do we need to use getattr
instead accessing via self
directly?
Ah, took me a while to understand, this is evil. :D The trick is that this attribute is only defined in child classes, right? Maybe a comment explaining this trick is warranted here.
) | ||
if getattr(self, '_EMIT_CODE_DEPRECATION_WARNING', True): | ||
warn_deprecation( | ||
'The `Code` class is deprecated. To create an instance, use the ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This warning might be a bit confusing if it's printed when user tries to create Code via CLI. At the same time the text is already long. 🤷
The `InstalledCode` and `PortableCode` have been introduced already some time ago as the refactored version of the legacy `Code` class. The latter has been deprecated for that reason, but for backwards compatibility reasons, the new implementations still need to keep the legacy class as a base class. Unfortunately, this meant that the deprecation warning was also shown when users instantiated an instance of the new classes, which would be confusing. The deprecation warning had already been moved from module level to the constructor of the `Code` class to prevent it from showing merely upon import of the `aiida.orm` package. As a final work around, the new classes define the `_EMIT_CODE_DEPRECATION_WARNING` class attribute which is checked in the `Code` constructor such that when set, the deprecation warning is skipped.
2ced904
to
aaaba67
Compare
…m#6407) The `InstalledCode` and `PortableCode` have been introduced already some time ago as the refactored version of the legacy `Code` class. The latter has been deprecated for that reason, but for backwards compatibility reasons, the new implementations still need to keep the legacy class as a base class. Unfortunately, this meant that the deprecation warning was also shown when users instantiated an instance of the new classes, which would be confusing. The deprecation warning had already been moved from module level to the constructor of the `Code` class to prevent it from showing merely upon import of the `aiida.orm` package. As a final work around, the new classes define the `_EMIT_CODE_DEPRECATION_WARNING` class attribute which is checked in the `Code` constructor such that when set, the deprecation warning is skipped.
The
InstalledCode
andPortableCode
have been introduced already some time ago as the refactored version of the legacyCode
class. The latter has been deprecated for that reason, but for backwards compatibility reasons, the new implementations still need to keep the legacy class as a base class. Unfortunately, this meant that the deprecation warning was also shown when users instantiated an instance of the new classes, which would be confusing.The deprecation warning had already been moved from module level to the constructor of the
Code
class to prevent it from showing merely upon import of theaiida.orm
package. As a final work around, the new classes define the_EMIT_CODE_DEPRECATION_WARNING
class attribute which is checked in theCode
constructor such that when set, the deprecation warning is skipped.