-
Notifications
You must be signed in to change notification settings - Fork 187
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
New item/attr setter for Dict nodes #4351
Conversation
The following two ways for setting (key:val) pairs in the dicts stored inside a Dict node were failing (the first one silently, the second one with an error message) but now are valid: dict_node = Dict() dict_node.dict.x = 'Set a value for x' dict_node['x'] = 'Overwrite the value for x'
Codecov Report
@@ Coverage Diff @@
## develop #4351 +/- ##
===========================================
- Coverage 79.15% 79.15% -0.00%
===========================================
Files 468 468
Lines 34616 34620 +4
===========================================
+ Hits 27397 27399 +2
- Misses 7219 7221 +2
Flags with carried forward coverage won't be shown. Click here to find out more.
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @ramirezfranciscof . Have some suggestions
aiida/orm/nodes/data/dict.py
Outdated
The dictionary key-value pairs are stored in the database in a column named `attributes`. | ||
We will then say that these are "database-attributes", or "attributes in a database sense". | ||
However, these are not "python-attributes" ("attributes in the python sense"), and can only |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I see the point of adding this, given that this was not clear for you either, this does not just apply to the Dict
nodes, but to all nodes. All node specific data are stored as attributes in the database. So although this may help clear things up, it may also confuse, since it may suggest that this is behavior specific to the Dict
plugin.
I would propose a text something like:
The dictionary contents of a `Dict` node are stored in the database as attributes. The dictionary can be initialized
through the `dict` argument in the constructor. After construction, values can be retrieved and updated through the
item getters and setters, respectively:
node['key'] = 'value'
Alternatively, the `dict` property returns an instance of the `AttributeManager` that can be used to get and set
values through attribute notation:
node.dict.key = 'value'
Note that trying to set dictionary values directly on the node, e.g. `node.key = value`, will not work as intended.
It will merely set the `key` attribute on the node instance, but will not be stored in the database. As soon as the
node goes out of scope, the value will be lost.
Finally, all dictionary mutations will be forbidden once the node is stored.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, would it still be ok to add something like this between the last two paragraphs?
node goes out of scope, the value will be lost.
Note that here it becomes apparent the difference in something being an "attribute of a node" (in
the sense that it is stored in the "attribute" column of the database when the node is stored) and
something being an "attribute of a python object" (in the sense of being able to modify and access
it as if it was a property of the variable, e.g. `node.key = value`). This is true of all types of
nodes, but it becomes more relevant for `Dict` nodes where one is constantly manipulating these
attributes.
Finally, all dictionary mutations will be forbidden once the node is stored.
Co-authored-by: Sebastiaan Huber <mail@sphuber.net>
c8f691d
to
6d66eae
Compare
6d66eae
to
9884b41
Compare
Thanks a lot @ramirezfranciscof ! |
Fixes #2883
The following two ways for setting (key:val) pairs in the dicts stored inside a Dict node were failing (the first one silently, the second one with an error message) but are now valid: