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

Restore proper mutability implementation of Node attributes #1111

Merged

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Feb 12, 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, WorkCalculation and Code 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

@sphuber
Copy link
Contributor Author

sphuber commented Feb 20, 2018

Suggested additions/changes:

  • Remove Sealable from AbstractCode, making the input_plugin, prepend_text and append_text immutable attributes. The hidden attribute should become an extra with the key _aiida_core_hidden.
  • Include a migration to change any set hidden attributes to an extra

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.
@sphuber sphuber force-pushed the fix_1109_mutable_attributes branch 2 times, most recently from ce87800 to 1f074c6 Compare February 22, 2018 15:54
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.
To make sure that it properly extends the mutable attributes from
AbstractCalculation, we subclass from AbstractCalculation instead
of just object
@giovannipizzi giovannipizzi merged commit 7fcea23 into aiidateam:release_v0.11.1 Feb 22, 2018
@sphuber sphuber deleted the fix_1109_mutable_attributes 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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants