From 67dab0f1a40ff657f7fd669d883100b973a469af Mon Sep 17 00:00:00 2001 From: Leopold Talirz <leopold.talirz@gmail.com> Date: Thu, 19 Aug 2021 17:49:05 +0200 Subject: [PATCH 1/4] Remove superfluous _validate from Data node The Data nodeclass overwrote the `_validate` function but (a) did no validation (b) included commented code that referenced a private git repository (c) returned `None` instead of `True`. The outcommented code involved validation of the `source` attribute and the referenced issue pointed out that the value of this attribute was not officially standardized (potentially leading users to using it in different ways). Since there has not been validation of this field since 2015, it seems safe to assume that it cannot be easily reintroduced at this point. --- aiida/orm/nodes/data/data.py | 22 +--------------------- aiida/orm/nodes/node.py | 12 +++++++----- 2 files changed, 8 insertions(+), 26 deletions(-) diff --git a/aiida/orm/nodes/data/data.py b/aiida/orm/nodes/data/data.py index dd6c7af6c0..e7cd15ec06 100644 --- a/aiida/orm/nodes/data/data.py +++ b/aiida/orm/nodes/data/data.py @@ -25,7 +25,7 @@ class Data(Node): Architecture note: Calculation plugins are responsible for converting raw output data from simulation codes to Data nodes. - Data nodes are responsible for validating their content (see _validate method). + Nodes are responsible for validating their content (see _validate method). """ _source_attributes = ['db_name', 'db_uri', 'uri', 'id', 'version', 'extras', 'source_md5', 'description', 'license'] @@ -351,23 +351,3 @@ def _get_converters(self): valid_format_names = [i[len(exporter_prefix):] for i in method_names if i.startswith(exporter_prefix)] valid_formats = {k: getattr(self, exporter_prefix + k) for k in valid_format_names} return valid_formats - - def _validate(self): - """ - Perform validation of the Data object. - - .. note:: validation of data source checks license and requires - attribution to be provided in field 'description' of source in - the case of any CC-BY* license. If such requirement is too - strict, one can remove/comment it out. - """ - # Validation of ``source`` is commented out due to Issue #9 - # (https://bitbucket.org/epfl_theos/aiida_epfl/issues/9/) - # super()._validate() - # if self.source is not None and \ - # self.source.get('license', None) and \ - # self.source['license'].startswith('CC-BY') and \ - # self.source.get('description', None) is None: - # raise ValidationError("License of the object ({}) requires " - # "attribution, while none is given in the " - # "description".format(self.source['license'])) diff --git a/aiida/orm/nodes/node.py b/aiida/orm/nodes/node.py index 0d9cce79e0..94b0cb5240 100644 --- a/aiida/orm/nodes/node.py +++ b/aiida/orm/nodes/node.py @@ -175,13 +175,15 @@ def initialize(self) -> None: self._incoming_cache = list() def _validate(self) -> bool: - """Check if the attributes and files retrieved from the database are valid. + """Validate information stored in Node object. - Must be able to work even before storing: therefore, use the `get_attr` and similar methods that automatically - read either from the DB or from the internal attribute cache. + For the :py:class:`~aiida.orm.Node` base class, this check is always valid. + Subclasses can override this method to perform additional checks + and should usually call ``super()._validate()``! - For the base class, this is always valid. Subclasses will reimplement this. - In the subclass, always call the super()._validate() method first! + This method is called automatically before storing the node in the DB. + Therefore, use :py:meth:`~aiida.orm.entities.Entity.get_attribute()` and similar methods that automatically + read either from the DB or from the internal attribute cache. """ # pylint: disable=no-self-use return True From 28a14da546aa4163aa67b2fb0897c4eb74c61488 Mon Sep 17 00:00:00 2001 From: Leopold Talirz <leopold.talirz@gmail.com> Date: Wed, 1 Sep 2021 10:16:34 +0200 Subject: [PATCH 2/4] Update aiida/orm/nodes/node.py Co-authored-by: Francisco Ramirez <ramirezfranciscof@users.noreply.github.com> --- aiida/orm/nodes/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiida/orm/nodes/node.py b/aiida/orm/nodes/node.py index 94b0cb5240..254f6156a5 100644 --- a/aiida/orm/nodes/node.py +++ b/aiida/orm/nodes/node.py @@ -179,7 +179,7 @@ def _validate(self) -> bool: For the :py:class:`~aiida.orm.Node` base class, this check is always valid. Subclasses can override this method to perform additional checks - and should usually call ``super()._validate()``! + and should usually call ``super()._validate()`` first! This method is called automatically before storing the node in the DB. Therefore, use :py:meth:`~aiida.orm.entities.Entity.get_attribute()` and similar methods that automatically From 6a1527815841b7234056f46c187cd97fff4af9be Mon Sep 17 00:00:00 2001 From: Leopold Talirz <leopold.talirz@gmail.com> Date: Thu, 2 Sep 2021 12:30:24 +0200 Subject: [PATCH 3/4] Update aiida/orm/nodes/node.py Co-authored-by: Francisco Ramirez <ramirezfranciscof@users.noreply.github.com> --- aiida/orm/nodes/node.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aiida/orm/nodes/node.py b/aiida/orm/nodes/node.py index 6550955fd8..08d25a37c0 100644 --- a/aiida/orm/nodes/node.py +++ b/aiida/orm/nodes/node.py @@ -185,7 +185,7 @@ def _validate(self) -> bool: and should usually call ``super()._validate()`` first! This method is called automatically before storing the node in the DB. - Therefore, use :py:meth:`~aiida.orm.entities.Entity.get_attribute()` and similar methods that automatically + Therefore, use :py:meth:`~aiida.orm.entities.EntityAttributesMixin.get_attribute()` and similar methods that automatically read either from the DB or from the internal attribute cache. """ # pylint: disable=no-self-use From 0cf8ee3e2424047bf01d4faae7b17fe6054d69b2 Mon Sep 17 00:00:00 2001 From: Francisco Ramirez <ramirezfranciscof@users.noreply.github.com> Date: Thu, 2 Sep 2021 14:38:57 +0200 Subject: [PATCH 4/4] Update aiida/orm/nodes/node.py --- aiida/orm/nodes/node.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aiida/orm/nodes/node.py b/aiida/orm/nodes/node.py index 08d25a37c0..2461b80f48 100644 --- a/aiida/orm/nodes/node.py +++ b/aiida/orm/nodes/node.py @@ -185,8 +185,8 @@ def _validate(self) -> bool: and should usually call ``super()._validate()`` first! This method is called automatically before storing the node in the DB. - Therefore, use :py:meth:`~aiida.orm.entities.EntityAttributesMixin.get_attribute()` and similar methods that automatically - read either from the DB or from the internal attribute cache. + Therefore, use :py:meth:`~aiida.orm.entities.EntityAttributesMixin.get_attribute()` and similar methods that + automatically read either from the DB or from the internal attribute cache. """ # pylint: disable=no-self-use return True