Skip to content

Commit

Permalink
Remove superfluous _validate from Data node
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
ltalirz committed Aug 19, 2021
1 parent c5e0118 commit 67dab0f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 26 deletions.
22 changes: 1 addition & 21 deletions aiida/orm/nodes/data/data.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']

Expand Down Expand Up @@ -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']))
12 changes: 7 additions & 5 deletions aiida/orm/nodes/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 67dab0f

Please sign in to comment.