ID 590466 - Calling setInput() in a node's onCreate callback will not succeed if the node is Copy/Pasted

Follow

Problem summary:
Calling setInput() in a node's onCreate callback will not succeed if the node is Copy/Pasted.
This issue does not seem to affect Group nodes.
 
Customer reported version:
Nuke 15.0v1
 
Customer reported platform:
Rhel 9
 
Steps to reproduce:
1) Launch Nuke and run the following code in the Script Editor:
# add an onCreate for all NoOp nodes, that connects them to the node named 'Grade1'def setNoOpInputOnCreate():     print("Running NoOp onCreate, input should be connected to Grade1")     n = nuke.thisNode()     n.setInput(0, nuke.toNode("Grade1"))     nuke.addOnCreate(setNoOpInputOnCreate, nodeClass="NoOp")
2) Create a Grade node in the Node Graph and deselect it.
3) Create a NoOp node and observe how it is automatically connected to the Grade1 node, according to the callback above.
4) Copy and Paste the NoOp node back into the Node Graph, and note that it is not connected to the Grade1 node:
 

 
Expected behavior:
Because the onCreate callback is run when any node is created, including when a node is pasted, it should be possible to automatically connect nodes by calling setInput() inside the callback.
 
Actual behavior:
When a node's onCreate callback includes setInput(), the desired input connection will not be set if the node was created by being pasted into the Node Graph.  
 
Workaround:
It is possible to produce the expected result from setInput() in an onCreate callback by utilizing a Pyside2 singleShot() like in the example below:
from PySide2.QtCore import QTimer def setNoOpInputOnCreate():     print("Running NoOp onCreate, input should be connected to Grade1")     n = nuke.thisNode()    QTimer.singleShot(0, lambda: n.setInput(0, nuke.toNode("Grade1"))) nuke.addOnCreate(setNoOpInputOnCreate, nodeClass="NoOp")
 
Reproduced by Support in:
Nuke 15.1v4 - Windows 10, macOS 14 Sonoma
Nuke 14.1v1 - Windows 10
Nuke 14.0v1 - Windows 10
Nuke 13.0v1 - Windows 10
Nuke 12.0v1 - Windows 10
 
Earliest version tested:
Nuke 12.0v1 - This issue appears to be in all tested versions of the product

    We're sorry to hear that

    Please tell us why