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

Follow

Problem summary
Using a Python contexts don't return to the original context after using group begin()/end() or with statements

Customer reported version
Nuke 12.2v7

Customer reported platform
Ubuntu

Steps to reproduce
1) Open Nuke
2) Press Ctrl+G twice to create a Group inside another Group
3) Run either of the following Python snippets in the Script Editor:
nested_node = nuke.toNode('Group2.Group1')nested_node.begin()nested_node.end()print(nuke.thisGroup().name()) # Expect the Root node, get the Group2 node
nested_node = nuke.toNode('Group2.Group1')with nested_node:    passprint(nuke.thisGroup().name()) # Expect the Root node, get the Group2 node

Expected behavior
For the context to return to what was used previously 

Actual behavior
The context moves to the parent context of the last context set

Workaround
Use group.run() to run specific functions in that group, but that requires creating lots of additional functions, making code harder to read:
def test():    print("test")nested_node = nuke.toNode('Group2.Group1')nested_node.run(test)print(nuke.thisGroup().name()) # Expect the Root node, get the Root node

Reproduced by Support in
Nuke 13.0v4 - Windows 10, CentOS 7.5, macOS Big Sur
Nuke 12.0v1 - Windows 10
Nuke 11.0v1 - Windows 10
Nuke 10.0v1 - Windows 10
Nuke 9.0v1 - Windows 10, macOS Big Sur

Earliest version tested
Nuke 9.0v1 - This issue appears to be in all versions of the product

    We're sorry to hear that

    Please tell us why