@@ -771,11 +771,25 @@ def _has_attr(self, parameter, subtype="in"):
771771 """Checks if a parameter is available as an input or output
772772 """
773773 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+
774780 attrname = hierarchy .pop ()
775781 nodename = hierarchy .pop ()
776782
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+
777790 targetworkflow = self
778- for workflowname in hierarchy :
791+ while hierarchy :
792+ workflowname = hierarchy .pop (0 )
779793 workflow = None
780794 for node in targetworkflow ._graph .nodes ():
781795 if node .name == workflowname :
@@ -784,6 +798,13 @@ def _has_attr(self, parameter, subtype="in"):
784798 break
785799 if workflow is None :
786800 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
787808 targetworkflow = workflow
788809
789810 targetnode = None
@@ -804,11 +825,12 @@ def _has_attr(self, parameter, subtype="in"):
804825 if not hasattr (targetnode .outputs , attrname ):
805826 return False
806827
828+ # Verify input does not already have an incoming connection
829+ # in the target workflow
807830 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
812834
813835 return True
814836
0 commit comments