Skip to content

Commit

Permalink
metdata now properly deep copied
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulSchweizer committed Sep 28, 2018
1 parent f7d6a32 commit 9c2bf79
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
6 changes: 4 additions & 2 deletions flowpipe/node.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import importlib
except ImportError:
pass
import copy
import imp
import inspect
import json
Expand Down Expand Up @@ -288,10 +289,11 @@ def __init__(self, func=None, outputs=None, name=None,

def __call__(self, **kwargs):
"""Create and return an instance of the Node."""
self.metadata.update(kwargs.pop("metadata", {}))
metadata = copy.deepcopy(self.metadata)
metadata.update(kwargs.pop("metadata", {}))
return self.__class__(func=self.func,
outputs=[o for o in self.outputs],
metadata=self.metadata,
metadata=metadata,
**kwargs)

def compute(self, *args, **kwargs):
Expand Down
10 changes: 10 additions & 0 deletions tests/test_convert_function_to_node.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,13 @@ def function(arg_1, arg_2="test_1", arg_3="test_2"):
assert node.inputs["arg_2"].value is "test_1"
assert node.inputs["arg_3"].value is "test_2"


def test_metadata_is_unique_for_each_node_created():
@Node(metadata={"key": [1, 2, 3]})
def function():
pass

node1 = function()
node2 = function()

assert node1.metadata is not node2.metadata

0 comments on commit 9c2bf79

Please sign in to comment.