I used to have all my external codes stored as old CodeNodes. Recently, I started moving everything to core.code.*, as suggested by deprecation warnings. I installed my new codes as, following example:
verdi code create core.code.containerized --config pq2.yaml
However, I still getting this error:
/.../aiida-qp2/lib/python3.9/site-packages/aiida/orm/nodes/data/code/legacy.py:42:
AiidaDeprecationWarning: The `Code` class is deprecated. To create an instance, use the
`aiida.orm.nodes.data.code.installed.InstalledCode` or
`aiida.orm.nodes.data.code.portable.PortableCode` for a "remote" or "local" code, respectively. If you are using this class to compare type, e.g. in `isinstance`, use
`aiida.orm.nodes.data.code.abstract.AbstractCode`. (this will be removed in v3)
Am I doing it right? I would not want to do it again.
It is possible that these warnings are red herrings. To keep backwards compatibility, the new code classes still had to subclass the deprecated Code class. Unfortunately, this means that the warning is displayed even when using a new code class. You can check the output of verdi code list. If the new codes have the type string core.code.installed, core.code.portable or core.code.containerized, you should be good.
Hi @sphuber, is there plan to remove this warning for user who use the new verdi code create, @edan-bainglass and I encounter this as well. I think we should not throw the warning for the using the correct operation.
I would like to, but I don’t think we can. The warning is only emitted if the deprecated Code class is instantiated. However, for backwards-compatibility, the new code classes still subclass that deprecated code, and so the warning is also thrown for the new classes. The only solution would be to get rid of the deprecation warning entirely, or break backwards-compatibility.
I think there is a solution, probably a bit hacky, but it’s OK for a deprecation warning I think, and I think it’s important to aim at not having deprecation warnings that are not needed, otherwise people will just ignore all of them.
In the “new” classes, before calling super().__init__(), one can do self._ISSUE_V3_CODE_WARNING = False.
Then in the __init__ of the legacy class, one wraps the code issuing the warning in a if getattr(self, "_ISSUE_V3_CODE_WARNING", True): clause.