@@ -1209,27 +1209,32 @@ def _break_supported_cycles_in_graph(self) -> Tuple[networkx.MultiDiGraph, Dict[
1209
1209
# sender_comp will be the last element of cycle and receiver_comp will be the first.
1210
1210
# So if cycle is [1, 2, 3, 4] we would call zip([1, 2, 3, 4], [2, 3, 4, 1]).
1211
1211
for sender_comp , receiver_comp in zip (cycle , cycle [1 :] + cycle [:1 ]):
1212
- # We get the key and iterate those as we want to edit the graph data while
1213
- # iterating the edges and that would raise.
1214
- # Even though the connection key set in Pipeline.connect() uses only the
1215
- # sockets name we don't have clashes since it's only used to differentiate
1216
- # multiple edges between two nodes.
1217
- edge_keys = list (temp_graph .get_edge_data (sender_comp , receiver_comp ).keys ())
1218
- for edge_key in edge_keys :
1219
- edge_data = temp_graph .get_edge_data (sender_comp , receiver_comp )[edge_key ]
1220
- receiver_socket = edge_data ["to_socket" ]
1221
- if not receiver_socket .is_variadic and receiver_socket .is_mandatory :
1222
- continue
1223
-
1224
- # We found a breakable edge
1225
- sender_socket = edge_data ["from_socket" ]
1226
- edges_removed [sender_comp ].append (sender_socket .name )
1227
- temp_graph .remove_edge (sender_comp , receiver_comp , edge_key )
1228
-
1229
- graph_has_cycles = not networkx .is_directed_acyclic_graph (temp_graph )
1230
- if not graph_has_cycles :
1231
- # We removed all the cycles, we can stop
1232
- break
1212
+ # for graphs with multiple nested cycles, we need to check if the edge hasn't
1213
+ # been previously removed before we try to remove it again
1214
+ edge_data = temp_graph .get_edge_data (sender_comp , receiver_comp )
1215
+ if edge_data is not None :
1216
+ # We get the key and iterate those as we want to edit the graph data while
1217
+ # iterating the edges and that would raise.
1218
+ # Even though the connection key set in Pipeline.connect() uses only the
1219
+ # sockets name we don't have clashes since it's only used to differentiate
1220
+ # multiple edges between two nodes.
1221
+ edge_keys = list (edge_data .keys ())
1222
+
1223
+ for edge_key in edge_keys :
1224
+ edge_data = temp_graph .get_edge_data (sender_comp , receiver_comp )[edge_key ]
1225
+ receiver_socket = edge_data ["to_socket" ]
1226
+ if not receiver_socket .is_variadic and receiver_socket .is_mandatory :
1227
+ continue
1228
+
1229
+ # We found a breakable edge
1230
+ sender_socket = edge_data ["from_socket" ]
1231
+ edges_removed [sender_comp ].append (sender_socket .name )
1232
+ temp_graph .remove_edge (sender_comp , receiver_comp , edge_key )
1233
+
1234
+ graph_has_cycles = not networkx .is_directed_acyclic_graph (temp_graph )
1235
+ if not graph_has_cycles :
1236
+ # We removed all the cycles, we can stop
1237
+ break
1233
1238
1234
1239
if not graph_has_cycles :
1235
1240
# We removed all the cycles, nice
0 commit comments