@@ -771,11 +771,25 @@ def _has_attr(self, parameter, subtype="in"):
771
771
"""Checks if a parameter is available as an input or output
772
772
"""
773
773
hierarchy = parameter .split ("." )
774
+
775
+ # Connecting to a workflow needs at least two values,
776
+ # the name of the child node and the name of the input/output
777
+ if len (hierarchy ) < 2 :
778
+ return False
779
+
774
780
attrname = hierarchy .pop ()
775
781
nodename = hierarchy .pop ()
776
782
783
+ def _check_is_already_connected (workflow , node , attrname ):
784
+ for _ , _ , d in workflow ._graph .in_edges (nbunch = node , data = True ):
785
+ for cd in d ["connect" ]:
786
+ if attrname == cd [1 ]:
787
+ return False
788
+ return True
789
+
777
790
targetworkflow = self
778
- for workflowname in hierarchy :
791
+ while hierarchy :
792
+ workflowname = hierarchy .pop (0 )
779
793
workflow = None
780
794
for node in targetworkflow ._graph .nodes ():
781
795
if node .name == workflowname :
@@ -784,6 +798,13 @@ def _has_attr(self, parameter, subtype="in"):
784
798
break
785
799
if workflow is None :
786
800
return False
801
+ # Verify input does not already have an incoming connection
802
+ # in the hierarchy of workflows
803
+ if subtype == "in" :
804
+ hierattrname = "." .join (hierarchy + [nodename , attrname ])
805
+ if not _check_is_already_connected (
806
+ targetworkflow , workflow , hierattrname ):
807
+ return False
787
808
targetworkflow = workflow
788
809
789
810
targetnode = None
@@ -804,11 +825,12 @@ def _has_attr(self, parameter, subtype="in"):
804
825
if not hasattr (targetnode .outputs , attrname ):
805
826
return False
806
827
828
+ # Verify input does not already have an incoming connection
829
+ # in the target workflow
807
830
if subtype == "in" :
808
- for _ , _ , d in targetworkflow ._graph .in_edges (nbunch = targetnode , data = True ):
809
- for cd in d ["connect" ]:
810
- if attrname == cd [1 ]:
811
- return False
831
+ if not _check_is_already_connected (
832
+ targetworkflow , targetnode , attrname ):
833
+ return False
812
834
813
835
return True
814
836
0 commit comments