From 81d20ec265fdfe6d0fd5bae1170e81974449f08f Mon Sep 17 00:00:00 2001 From: Bonan Zhu <33688599+zhubonan@users.noreply.github.com> Date: Mon, 20 Feb 2023 10:07:35 +0000 Subject: [PATCH 1/3] Update custom data plugin documentation Warn the user that the constructor is not called when the node is loaded from the database at a later time. --- docs/source/topics/data_types.rst | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/source/topics/data_types.rst b/docs/source/topics/data_types.rst index f0d6cfbedc..fb0b1e8bcb 100644 --- a/docs/source/topics/data_types.rst +++ b/docs/source/topics/data_types.rst @@ -1149,6 +1149,8 @@ Therefore, we have to override the constructor :meth:`~aiida.orm.nodes.node.Node .. warning:: For the class to function properly, the signature of the constructor **cannot be changed** and the constructor of the parent class **has to be called**. + Note that the constructor is **NOT** called when the node is loaded from the database afterwards. + Hence, one should avoid setting attributes that correspond to the sorted data inside the ``__init__`` itself. Instead, use the ``@property`` approach to provide easy access to any sorted data instead (see below). Before calling the constructor of the base class, we have to remove the ``value`` keyword from the keyword arguments ``kwargs``, because the base class will not expect it and will raise an exception if left in the keyword arguments. The final step is to actually *store* the value that is passed by the caller of the constructor. From 09a9742a7c0155e0efbc7468b74ca76475598ec6 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 20 Feb 2023 10:10:49 +0000 Subject: [PATCH 2/3] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- docs/source/topics/data_types.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/topics/data_types.rst b/docs/source/topics/data_types.rst index fb0b1e8bcb..09cba1f931 100644 --- a/docs/source/topics/data_types.rst +++ b/docs/source/topics/data_types.rst @@ -1149,8 +1149,8 @@ Therefore, we have to override the constructor :meth:`~aiida.orm.nodes.node.Node .. warning:: For the class to function properly, the signature of the constructor **cannot be changed** and the constructor of the parent class **has to be called**. - Note that the constructor is **NOT** called when the node is loaded from the database afterwards. - Hence, one should avoid setting attributes that correspond to the sorted data inside the ``__init__`` itself. Instead, use the ``@property`` approach to provide easy access to any sorted data instead (see below). + Note that the constructor is **NOT** called when the node is loaded from the database afterwards. + Hence, one should avoid setting attributes that correspond to the sorted data inside the ``__init__`` itself. Instead, use the ``@property`` approach to provide easy access to any sorted data instead (see below). Before calling the constructor of the base class, we have to remove the ``value`` keyword from the keyword arguments ``kwargs``, because the base class will not expect it and will raise an exception if left in the keyword arguments. The final step is to actually *store* the value that is passed by the caller of the constructor. From 3730a5044a807b1f70024dcd2ec3ac04953d6ddc Mon Sep 17 00:00:00 2001 From: Bonan Zhu <33688599+zhubonan@users.noreply.github.com> Date: Tue, 21 Feb 2023 07:21:53 +0000 Subject: [PATCH 3/3] Update docs/source/topics/data_types.rst Co-authored-by: Sebastiaan Huber --- docs/source/topics/data_types.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/source/topics/data_types.rst b/docs/source/topics/data_types.rst index 09cba1f931..a2eb282447 100644 --- a/docs/source/topics/data_types.rst +++ b/docs/source/topics/data_types.rst @@ -1149,8 +1149,8 @@ Therefore, we have to override the constructor :meth:`~aiida.orm.nodes.node.Node .. warning:: For the class to function properly, the signature of the constructor **cannot be changed** and the constructor of the parent class **has to be called**. - Note that the constructor is **NOT** called when the node is loaded from the database afterwards. - Hence, one should avoid setting attributes that correspond to the sorted data inside the ``__init__`` itself. Instead, use the ``@property`` approach to provide easy access to any sorted data instead (see below). + Note also that the constructor is **NOT** called when the node is loaded from the database afterwards. + Hence, one should not rely on initializing instance attributes inside the ``__init__`` itself (here "attributes" does not refer to the data stored in the database, but the normal Python understanding of attributes that class instances have). Before calling the constructor of the base class, we have to remove the ``value`` keyword from the keyword arguments ``kwargs``, because the base class will not expect it and will raise an exception if left in the keyword arguments. The final step is to actually *store* the value that is passed by the caller of the constructor.