Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

runtime properties dirty flag is not set when updating objects stored in runtime properties #992

Open
mareklabonarski opened this issue Feb 16, 2022 · 0 comments

Comments

@mareklabonarski
Copy link

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant