Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove superfluous _validate from Data node #5089

Merged
merged 6 commits into from
Sep 2, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -178,13 +178,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()`` first!

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
ltalirz marked this conversation as resolved.
Show resolved Hide resolved
read either from the DB or from the internal attribute cache.
"""
# pylint: disable=no-self-use
return True
Expand Down