Skip to content
This repository has been archived by the owner on Nov 28, 2023. It is now read-only.

Commit

Permalink
Merge eb8bafe into 7a4eab2
Browse files Browse the repository at this point in the history
  • Loading branch information
masci committed Nov 16, 2023
2 parents 7a4eab2 + eb8bafe commit 199633c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions canals/pipeline/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,9 @@ def run(self, data: Dict[str, Any], debug: bool = False) -> Dict[str, Any]: # p

for node_name, input_data in data.items():
for socket_name, value in input_data.items():
# Make a copy of the input value so components don't need to
# take care of mutability.
value = deepcopy(value)
connection = Connection(
None, None, node_name, self.graph.nodes[node_name]["input_sockets"][socket_name]
)
Expand Down
27 changes: 27 additions & 0 deletions test/pipeline/integration/test_mutable_inputs.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
from typing import List

from canals import Pipeline, component
from sample_components import StringListJoiner


@component
class InputMangler:
@component.output_types(mangled_list=List[str])
def run(self, input_list: List[str]):
input_list.append("extra_item")
return {"mangled_list": input_list}


def test_mutable_inputs():
pipe = Pipeline()
pipe.add_component("mangler1", InputMangler())
pipe.add_component("mangler2", InputMangler())
pipe.add_component("concat1", StringListJoiner())
pipe.add_component("concat2", StringListJoiner())
pipe.connect("mangler1", "concat1")
pipe.connect("mangler2", "concat2")

mylist = ["foo", "bar"]

result = pipe.run(data={"mangler1": {"input_list": mylist}, "mangler2": {"input_list": mylist}})
assert result["concat1"]["output"] == result["concat1"]["output"] == ["foo", "bar", "extra_item"]

0 comments on commit 199633c

Please sign in to comment.