Skip to content

Restore proper mutability implementation of Node attributes#1181

Merged
giovannipizzi merged 13 commits into
aiidateam:workflowsfrom
sphuber:fix_1109_mutable_attributes_workflows_branch
Feb 22, 2018
Merged

Restore proper mutability implementation of Node attributes#1181
giovannipizzi merged 13 commits into
aiidateam:workflowsfrom
sphuber:fix_1109_mutable_attributes_workflows_branch

Conversation

@sphuber
Copy link
Copy Markdown
Contributor

@sphuber sphuber commented Feb 22, 2018

Fixes #1109

The concept of attribute immutability has been properly reinstated. The current conception of node attribute mutability is the following.

  • Attributes of all nodes are immutable when Node is stored
  • Attributes of nodes with the Sealable mixin are immutable when the node is sealed or when stored and the attribute is not in the _updatable_attributes tuple

To enforce this behavior, the is_stored check is moved back into the _set_attr and _del_attr methods of the AbstractNode class. The Sealable mixin, allows the AbstractCalculation and WorkCalculation subclasses of Node to define a tuple of _updatable_attributes that can be mutated as long as the node is not sealed.

The updatable attributes that were defined for the Code class, input_plugin, prepend_text, append_text and hidden have been removed, allowing the Sealable mixin to be removed. The first three really should be immutable as changing them can really affect the outcome of calculations run with that code. The hidden attribute is more a meta data attribute, specific to the user that owns the code and therefore better belongs in the extras of the node

…_release

Enable the Trusty platform and postgres 9.5 on Travis
The check for node attribute immutability, i.e. when a node is stored
its attributes are to be immutable, was moved out of the base Node
class and moved to the Data class and the SealableWithUpdatableAttributes
mixin, in order to allow for Calculation attributes that needed to
be mutable even after storing the node, e.g. the calculation state.
However, the logic was improperly implemented and not applied everywhere
leaving certain nodes with all attributes mutable even after being stored.
To prevent this error from happening in the future, we move the check
back to the Node class. The calculation classes will have to override
this behavior in the future to allow for updatable attributes
The attribues of the Node class become immutable once the node is
stored. However, for some Node subclasses one needs to allow for
certain attributes to be updatable even after storing. An example
is the Calculation class. For it to run, it needs to be stored,
however its running state is stored in an attribute which needs to
be updated despite the underlying node already being stored.

To solve this we introduce the Sealable mixin, which can defined a
tuple of updatable attributes that are mutable even when the node
is stored. It also provides the 'sealed' attribute which when set
even the updatable attributes become immutable
…utes

This was already done in PR aiidateam#652 that was merged into develop but
needs to be done in this branch as well for consistency, which will
be merged into the v0.11.1 patch release
The 'input_plugin', 'append_text' and 'prepend_text' attributes should not
really be updatable as they can really alter the behavior of the code. For
that reason we remove them from the updatable_attributes. The 'hidden'
attribute can be turned into an extra, as it really is more meta-data that
is only pertinent to the user that owns the code. That leaves no updatable
attributes for this class, which means the Sealable mixin can be removed.
The -a switch for verdi code list was broken because it filtered on
the hidden attribute in a hardcoded way and just checked if the hidden
property was not True. However if it is not set at all, which is the
default, then it should also be ignored.
@sphuber sphuber force-pushed the fix_1109_mutable_attributes_workflows_branch branch 2 times, most recently from aaab0f1 to fa00b5f Compare February 22, 2018 17:01
To make sure that it properly extends the mutable attributes from
AbstractCalculation, we subclass from AbstractCalculation instead
of just object
@sphuber sphuber force-pushed the fix_1109_mutable_attributes_workflows_branch branch from fa00b5f to 4862307 Compare February 22, 2018 18:36
@giovannipizzi giovannipizzi merged commit d37968b into aiidateam:workflows Feb 22, 2018
@sphuber sphuber deleted the fix_1109_mutable_attributes_workflows_branch branch February 22, 2018 21:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants