@@ -1392,22 +1392,33 @@ def _deserialize(self, data, relative_pos=False, pos=None, set_parent=True):
13921392 'output_ports' : n_data ['output_ports' ]
13931393 })
13941394
1395+ def get_node_by_id (nid ):
1396+ # if nid referes to a node created during deserialization,
1397+ # it may have a new id. get the new id.
1398+ if nid in nodes :
1399+ print (f'{ nid } , { nodes [nid ].id } ' )
1400+ nid = nodes [nid ].id
1401+ return self .model .nodes .get (nid )
1402+
13951403 # build the connections.
13961404 for connection in data .get ('connections' , []):
13971405 nid , pname = connection .get ('in' , ('' , '' ))
1398- in_node = nodes . get (nid )
1406+ in_node = get_node_by_id (nid )
13991407 if not in_node :
14001408 continue
14011409 in_port = in_node .inputs ().get (pname ) if in_node else None
14021410
14031411 nid , pname = connection .get ('out' , ('' , '' ))
1404- out_node = nodes . get (nid )
1412+ out_node = get_node_by_id (nid )
14051413 if not out_node :
14061414 continue
14071415 out_port = out_node .outputs ().get (pname ) if out_node else None
14081416
14091417 if in_port and out_port :
1410- self ._undo_stack .push (PortConnectedCmd (in_port , out_port ))
1418+ # only connect if input port is not connected yet or input port can have multiple connections.
1419+ # important when duplicating nodes.
1420+ if not in_port .model .connected_ports or in_port .model .multi_connection :
1421+ self ._undo_stack .push (PortConnectedCmd (in_port , out_port ))
14111422
14121423 node_objs = list (nodes .values ())
14131424 if relative_pos :
0 commit comments