ID 267419 - Using a Python contexts don't return to the original context after using being()/end() or with statements

Follow

Problem summary
Gizmo input connections break when a callback calls inside the gizmo

Customer reported version
nuke.10.0v4

Customer reported platform

Steps to reproduce

1) Open Nuke

2) Create an empty Group node

3) Export it as a gizmo to your .nuke directory

4) Re-open Nuke

5) Run the Update command in the DAG

6) Create your gizmo and attach an input and output network of nodes

7) Copy and paste the node tree, everything will be connected

8) Run the below code in the script editor:

def helloWorld():    print "before"    try:        with nuke.thisNode():            print "middle"    except:         pass    print "after"nuke.addOnCreate(helloWorld)
9) Copy and paste the node tree again, the Gizmo node will no longer have it's input connection 


Note:
The below code also causes the same issue

def helloWorld():    print "before"    try:         nuke.thisNode().begin()            print "middle"         nuke.thisNode().end()                     except:         pass    print "after"nuke.addOnCreate(helloWorld)
Workaround
Use .run() on the Gizmo to call functions with the Gizmo's context:
 

def myGizmoOnCreate():  print("in the context of the gizmo")  for n in nuke.allNodes():    print(n.name())myGizmoClassName = "empty"def onCreateCallback():  n = nuke.thisNode()  if n and n.Class() == myGizmoClassName:    n.run(myGizmoOnCreate)nuke.addOnCreate(onCreateCallback)
 
Reproduced by support
This problem has been reproduced on:
Nuke 10.5v2 - Windows 10
Nuke 10.5v1 - Windows 10 - CentOS 6.8 - MacOSX 10.12
Nuke 10.0v6 - Windows 10
Nuke 10.0v1 - Windows 10
Nuke 9.0v9 - Windows 10
Nuke 8.0v6 - Windows 10

Expected behaviour
For the gizmo to maintain it's connections when copy and pasted

Actual behaviour
It lost it's input connections when being copy and pasted and a callback calls inside it

    We're sorry to hear that

    Please tell us why