@@ -1293,6 +1293,7 @@ def _deserialize(self, data, relative_pos=False, pos=None):
12931293
12941294 # build the nodes.
12951295 nodes = {}
1296+ new_node_connections = {}
12961297 for n_id , n_data in data .get ('nodes' , {}).items ():
12971298 identifier = n_data ['type_' ]
12981299 node = self ._node_factory .create_node_instance (identifier )
@@ -1318,21 +1319,27 @@ def _deserialize(self, data, relative_pos=False, pos=None):
13181319 # build the connections.
13191320 for connection in data .get ('connections' , []):
13201321 nid , pname = connection .get ('in' , ('' , '' ))
1321- in_node = nodes .get (nid )
1322+ in_node = nodes .get (nid ) or self . get_node_by_id ( nid )
13221323 if not in_node :
13231324 continue
13241325 in_port = in_node .inputs ().get (pname ) if in_node else None
13251326
13261327 nid , pname = connection .get ('out' , ('' , '' ))
1327- out_node = nodes .get (nid )
1328+ out_node = nodes .get (nid ) or self . get_node_by_id ( nid )
13281329 if not out_node :
13291330 continue
13301331 out_port = out_node .outputs ().get (pname ) if out_node else None
13311332
13321333 if in_port and out_port :
1333- self ._undo_stack .push (PortConnectedCmd (in_port , out_port ))
1334-
1335- node_objs = list (nodes .values ())
1334+ # only connect if input port is not connected yet or input port
1335+ # can have multiple connections.
1336+ # important when duplicating nodes.
1337+ allow_connection = any ([not in_port .model .connected_ports ,
1338+ in_port .model .multi_connection ])
1339+ if allow_connection :
1340+ self ._undo_stack .push (PortConnectedCmd (in_port , out_port ))
1341+
1342+ node_objs = nodes .values ()
13361343 if relative_pos :
13371344 self ._viewer .move_nodes ([n .view for n in node_objs ])
13381345 [setattr (n .model , 'pos' , n .view .xy_pos ) for n in node_objs ]
0 commit comments