-
Notifications
You must be signed in to change notification settings - Fork 16
Description
In a python script, when updating an object being stored in runtime properties, for example:
intial script:
ctx.instance.runtime_properties['a_list'] = []
ctx.instance.runtime_properties['a_dict'] = {}then, in execution of another script:
ctx.instance.runtime_properties['a_list'].append(1)
ctx.instance.runtime_properties['a_dict'].update({
'key1': 'value1'
})node instance will not be updated, and the changes made will not be saved.
If we did additionally any assignment to runtime properties:
ctx.instance.runtime_properties['a_list'].append(1)
ctx.instance.runtime_properties['a_dict'].update({
'key1': 'value1'
})
ctx.instance.runtime_properties['a_var'] = 'some_value'the internal "dirty" flag of runtime properties object will be set and node instance will have runtime properties updated according to changes made.
I can see the whole mechanism of detecting changes to runtime properties, being object of DirtyTrackingDict is based on setting the .dirty flag, but only in case of direct assignments or update method call.
If we do the same on objects which are nested in runtime properties, the mechanism does not work and probably it will be hard to make it working in current design.
A potential solution to it could be:
- before executing the script, make a deepcopy of runtime properties
- execute the script
- compare runtime properties with the copy done intially
initial_runtime_properties = copy.deepcopy(ctx.instance.runtime_properties)
run_script(ctx, ...)
if ctx.instance.runtime_properties != initial_runtime_properties:
ctx.instance.runtime_properties._set_changed() # what sets .dirty=True