Strange property editing?

I came across this issue when trying to dynamically create a table. I copied a "column" object to the Custom property section of the table to use in my script to create multiple instances, but after I set a variable equal to that "column" object, editing my variable modifies the "column" object in my Custom properties.

Thought this was very confusing behavior. Am I missing something?

Cheers,
Lucas

No, this is deliberate, to mimic python behavior of lists and dictionaries. Variable assignment with objects is assignment of a reference, not a copy of the object.

2 Likes

For this and other myriad reasons, never use "side effects" from a transform. Transforms should be written as functionally "pure" expressions (in the computer science sense of the word) in essentially every case.

Rebinding property tree reference objects can also cause weird behavior with deeply nested objects/arrays, if I remember correctly. Prefer reading to and writing from fully qualified paths (in your e.g. property change scripts, not transforms) at the very beginning and very end of your scripts.

Even better, rewrite any significant business logic to live as pure functions in the project library, and only pass parameters or handle return values in component scripts.

1 Like

Thank you for the answers. Any recommendations then on how to create multiple instances of this column object within my script?

Define a base instance in a constant in your project library script (outside any function). Make copies of this base dictionary whenever you want to prepare a new one. (Simply pass the original to the dict() constructor.)