Dynamically setting GHPython nodes gives error in V8?

For some of my Grasshopper components, I like to have them configure themselves dynamically based on some user-input. This normally works just fine. However I have noticed now in Rhino-8 that I’m getting a small error in certain situations:


Assuming I have a GHPython component that looks roughly like this (note, this a very, very simplified example without any validation or error-handling, just to show the issue):

from Grasshopper.Kernel import GH_ParamAccess
from GhPython import Component

input_sets = {
    "inputs_a" : {
        1: {"name":"_example_item_a", "access":GH_ParamAccess.item},
        2: {"name":"_example_list_a", "access":GH_ParamAccess.list},
    },
    "inputs_b" : {
        1: {"name":"_example_item_b", "access":GH_ParamAccess.item},
        2: {"name":"_example_list_b", "access":GH_ParamAccess.list},
    },
}

input_set = input_sets[_type]

for k, v in input_set.items():
    input_node = ghenv.Component.Params.Input[k]
    input_node.NickName = v["name"]
    input_node.Name = v["name"]
    input_node.Access = v["access"]
    input_node.TypeHint = Component.NewStrHint()

for input_node in ghenv.Component.Params.Input:
    if input_node.Access == GH_ParamAccess.item:
        input_ = list(input_node.VolatileData[0])[0]
    elif input_node.Access == GH_ParamAccess.list:
        input_ = [str(_) for _ in input_node.VolatileData[0]]
    elif input_node.Access == GH_ParamAccess.tree:
        input_ = None # Ignore
    else:
        input_ = None # Ignore
    
    print "{} = {}".format(input_node.Name, input_)

This works fine. I can change the input nodes based on the ‘type’ selected by the user. The issue comes if I change the Access type of a node from item to list. So for instance, if ‘inputs_a’ has an ‘item’ type at first, but ‘inputs_b’ has a ‘list’ type for that node

....
input_sets = {
    "inputs_a" : {
        1: {"name":"_example_item_a", "access":GH_ParamAccess.item},
        2: {"name":"_example_list_a", "access":GH_ParamAccess.item}, # <----- ITEM ACCESS
    },
    "inputs_b" : {
        1: {"name":"_example_item_b", "access":GH_ParamAccess.item},
        2: {"name":"_example_list_b", "access":GH_ParamAccess.list}, #<---- LIST ACCESS
    },
}
...

then I get a funny error when I change the configuration:

Runtime error (InvalidOperationException): GetDataList() can only be called on a parameter with access set to GH_ParamAccess.list

Traceback (most recent call last):
SystemError: GetDataList() can only be called on a parameter with access set to GH_ParamAccess.list

However, if I mouse-click-drag and reconnect the panel input, the error goes away…

I wonder what I can do to avoid this error and where I’m going wrong in my setup? Not sure why its happening, or what I should try and investigate to resolve it? Any thoughts are much appreciated!

thanks,
@ed.p.may


Environment:

  • Macbook 2021, Apple M1 Max
  • macOS 13.6.3 (Ventura)
  • Rhino Version 8 (8.5.24065.13002, 2024-03-05)

Example File:

example.gh (6.1 KB)