Skip to content

Commit

Permalink
Docs: Add warning that Data constructor is not called on loading (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
zhubonan authored Feb 22, 2023
1 parent 4b4b007 commit 34f7dee
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions docs/source/topics/data_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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 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.
Expand Down

0 comments on commit 34f7dee

Please sign in to comment.