Skip to content

Do not allow the copy or deepcopy of Node, except for Data #1705

Merged
sphuber merged 2 commits into
developfrom
fix_1699_copy_deepcopy_nodes
Jul 6, 2018
Merged

Do not allow the copy or deepcopy of Node, except for Data #1705
sphuber merged 2 commits into
developfrom
fix_1699_copy_deepcopy_nodes

Conversation

@sphuber
Copy link
Copy Markdown
Contributor

@sphuber sphuber commented Jun 29, 2018

Fixes #1699

We explicitly disallow calling the functions copy and deepcopy
from the python copy module on a Node instance. The reason is that
the behavior of this for a Calculation node, with respect to what
should be returned and how this would affect the graph, is not clear.
Rather, to clone a Calculation, the caching mechanism should be
used or a new ProcessBuilder could be generated from a completed
Process that would recreate the necessary inputs that could then
easily be relaunched.

For Data nodes, the behavior can be defined a bit better. Therefore
we allow to call deepcopy on a Data node, which will call the internal
clone method, which will return an identical, but unstored, clone of
the original Data node. The clone will have no links and a newly
generated UUID.

@sphuber sphuber added type/bug priority/critical-blocking must be resolved before next release labels Jun 29, 2018
@sphuber sphuber requested review from giovannipizzi and muhrin June 29, 2018 16:35
@sphuber sphuber force-pushed the fix_1699_copy_deepcopy_nodes branch 3 times, most recently from 63db99b to 24ca54e Compare June 30, 2018 07:47
@codecov-io
Copy link
Copy Markdown

codecov-io commented Jun 30, 2018

Codecov Report

Merging #1705 into develop will increase coverage by 0.01%.
The diff coverage is 86.66%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #1705      +/-   ##
===========================================
+ Coverage     56.4%   56.41%   +0.01%     
===========================================
  Files          275      275              
  Lines        33931    33912      -19     
===========================================
- Hits         19139    19132       -7     
+ Misses       14792    14780      -12
Impacted Files Coverage Δ
aiida/orm/implementation/sqlalchemy/node.py 68.02% <ø> (-0.74%) ⬇️
aiida/orm/implementation/django/node.py 73.15% <ø> (-0.64%) ⬇️
aiida/work/processes.py 95.2% <0%> (ø) ⬆️
aiida/orm/implementation/general/node.py 77.99% <92.85%> (+0.21%) ⬆️
aiida/common/folders.py 80.23% <0%> (+0.59%) ⬆️
aiida/backends/djsite/db/models.py 75.97% <0%> (+0.88%) ⬆️
aiida/backends/djsite/globalsettings.py 86.84% <0%> (+5.26%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 777c16c...220c3ea. Read the comment docs.

@muhrin
Copy link
Copy Markdown
Contributor

muhrin commented Jul 1, 2018

Why is this blocked Seb? Do you want a review or should it wait?

@sphuber
Copy link
Copy Markdown
Contributor Author

sphuber commented Jul 2, 2018

It was blocked by #1704 but that is now merged, so I will rebase and then it is ready for review

@sphuber sphuber force-pushed the fix_1699_copy_deepcopy_nodes branch from 24ca54e to 6e332b9 Compare July 2, 2018 06:59
@sphuber sphuber changed the title [BLOCKED] Do not allow the copy or deepcopy of Node, except for Data Do not allow the copy or deepcopy of Node, except for Data Jul 2, 2018
@sphuber sphuber force-pushed the fix_1699_copy_deepcopy_nodes branch from 6e332b9 to 80cca3b Compare July 2, 2018 07:18
muhrin
muhrin previously requested changes Jul 3, 2018
Comment thread aiida/orm/data/__init__.py Outdated
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we raise on is_stored asking the user to use clone instead.

@sphuber
Copy link
Copy Markdown
Contributor Author

sphuber commented Jul 6, 2018

@muhrin I have addressed the issue and its ready for review

@sphuber sphuber force-pushed the fix_1699_copy_deepcopy_nodes branch from 9abe1c7 to ced9d11 Compare July 6, 2018 08:47
sphuber added 2 commits July 6, 2018 17:53
We explicitly disallow calling the functions copy and deepcopy
from the python copy module on a Node instance. The reason is that
the behavior of this for a Calculation node, with respect to what
should be returned and how this would affect the graph, is not clear.
Rather, to clone a Calculation, the caching mechanism should be
used or a new ProcessBuilder could be generated from a completed
Process that would recreate the necessary inputs that could then
easily be relaunched.

For Data nodes, the behavior can be defined a bit better. Therefore
we allow to call deepcopy on a Data node, which will call the internal
clone method, which will return an identical, but unstored, clone of
the original Data node. The clone will have no links and a newly
generated UUID.
Deep copying an unstored node is fine however and just pipes
through to the clone method.
@sphuber sphuber force-pushed the fix_1699_copy_deepcopy_nodes branch from ced9d11 to 220c3ea Compare July 6, 2018 15:54
@sphuber
Copy link
Copy Markdown
Contributor Author

sphuber commented Jul 6, 2018

@giovannipizzi could you please give this a look so it can be merged. It can be quite a problem for people running aiida-quantumespresso on develop

Copy link
Copy Markdown
Member

@giovannipizzi giovannipizzi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good for me!
Does this need also @muhrin's review to get unlocked?

@sphuber
Copy link
Copy Markdown
Contributor Author

sphuber commented Jul 6, 2018

He already was agreed provided I made the one update, which I did, so I am pretty sure he is on board_

@sphuber sphuber dismissed muhrin’s stale review July 6, 2018 21:37

I implemented the desired change

@sphuber sphuber merged commit 3ad95ef into develop Jul 6, 2018
@sphuber sphuber deleted the fix_1699_copy_deepcopy_nodes branch July 6, 2018 21:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

priority/critical-blocking must be resolved before next release type/bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants