ID 331492 - Using Python root knob expressions on launch cause exceptions

Follow

Problem summary
Python knob expressions have the functionality to use the “Script Directory” button on the Root node, that sets the project_directory knob to [python {nuke.script_directory()}].
 
However, this functionality has limitations during certain operations.

One example is script loading, as the Root node is invalidated several times during the course of a script load operation, Python expressions that attempt to read or write knob values will cause the following exception: ValueError: A PythonObject is not attached to a node

This behaviour will break the opened Nuke script if it is used to drive the following knob:customOCIOConfigPath  (for example, to read a config path relative to the script file’s location). 

When the script is opened, Nuke will try to evaluate this knob to build the internal OCIO config, but the expression will error, Nuke will load its default config, and the script will end up in a broken state with all OCIO-related Colorspace knobs reset to index 0.


Customer reported version
Nuke11.1v1

Customer reported platform
Windows 7

Steps to reproduce

1) Setup your project folder with a custom OCIOConfig.

2) Open a new Nuke project, create an OCIOColorSpace node with your custom Colorspaces.

3) Within the project settings ( keyboard shortcut in your Node Graph: 's' ), add the following:


4) Save and exit Nuke.

5) Reopen Nuke

Result: Nuke will call an exception and load its default config, the script will end broken with all OCIO-related Colorspace knobs reset.

Workaround
Using a TCL expression instead such as (" [file dirname [value name]] ") will function as expected.

For example:
​​


Reproduced by support
This bug has been reproduced in:
Nuke11.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke11.0v3 - Windows 7 - Mac10.12 - CentOS6.9
Nuke11.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.5v7 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.5v1 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.0v6 - Windows 7 - Mac10.12 - CentOS6.9
Nuke10.0v1 - Windows 7 - Mac10.12 - CentOS6.9
Unable to reproduce the bug in:
Nuke9.0v9 - Windows 7 - Mac10.12 - CentOS6.9

Earliest version tested
Nuke9.0v9- This feature did not exist before this version (OCIO colorspaces were updated with Nuke10.0)
Expected behaviour
Calling Python root knob expressions should cause no exceptions.

Actual behaviour
When calling Python root knob expression on launch, it causes exceptions.  (In the above case, resetting the OCIOConfig)

    We're sorry to hear that

    Please tell us why