# \[bug-16904\]Behavior of perspective custom properties vs \[pj\]ython data structures

**URL:** <https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295>\
**Category:** Ignition\
**Created:** [August 2, 2020, 5:47pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295 "2020-08-02T17:47:39Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [August 2, 2020, 5:47pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/1 "2020-08-02T17:47:39Z")

</div>

Is it legal to initialize/set perspective custom properties out of a python dictionary? I’ve got mixed results and even seemingly bugs, for example with the following code (put it in a perspective button “onClick” event):

```auto
session = self.session
# this *sometimes* sets session.custom.foo to BAR, sometimes leaves it at its previous value
session.custom = {'foo': "BAR"}
# this *sometimes* erases all properties, sometimes leaves foo
session.custom = {}

```

If what I’m doing isn’t reliable, what’s a good way to bulk set dozens of perspective custom properties starting from a python dictionary or array?

---

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [August 4, 2020, 9:28am UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/2 "2020-08-04T09:28:01Z")

</div>

Also, ho can I access a custom property whose name I have in a variable? For example, I have session.custom.foo and session.custom.bar, and x = ‘bar’.  
How do I reference session.custom.$x (not valid of course, I’m looking for the right syntax) ?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 4, 2020, 12:19pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/3 "2020-08-04T12:19:23Z")

</div>

Try `getattr(session.custom, x)` and `setattr(session.custom, x, newValue)`.

---

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [August 4, 2020, 1:12pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/4 "2020-08-04T13:12:35Z")

</div>

Thanks, how does this work with complex nested hierarchies? Do I just do `getattr(session.custom, 'foo.bar.baz[0].quu')` or should I first get `baz = session.custom.foo.bar.baz[0]` (if that’s the right syntax) and then `getattr(baz, 'quu')` ?

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [August 4, 2020, 1:21pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/5 "2020-08-04T13:21:53Z")

</div>

Python’s `getattr` function works one level at a time. Supply the deepest constant level as the first argument, with the corresponding next level of dynamic property name. Perform array subscript lookups directly on that level of object.

---

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [August 4, 2020, 3:31pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/7 "2020-08-04T15:31:58Z")

</div>

I’ve got it to work more or less, thanks. Still, I don’t seem to be able to completely delete all custom properties; the following all fail for various reasons:

```auto
session.custom = {} # no change at all
setattr(session, 'custom', {}) # no change at all
delattr(session, 'custom') # object has no attribute "custom"

```

EDIT: Now, _this_ seems to work to delete all properties:

```auto
for prop in session.custom:
    delattr(session.custom, prop)

```

Still it feels a bit awkward to have to go through all these contortions. It would be much better if just assigning a dictionary worked out of the box (I haven’t found the contrary explicitly stated, and instead found references in this forum suggesting that it should work; yet it doesn’t).

---

<div class="post-metadata">

**Author:** ![paul-griffith](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/paul-griffith/32/37249_2.png) [@paul-griffith](https://forum.inductiveautomation.com/u/paul-griffith)\
**Post date:** [August 4, 2020, 3:58pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/8 "2020-08-04T15:58:57Z")

</div>

Looking at the code, both of your first examples “should” work - I think there’s a bug in the way the property tree tries to ‘merge’ values between what it already has and what it’s getting assigned. I’ll file a ticket for it.  
I wouldn’t expect `delattr` to work on the top level (an actual scope of `custom`, `props`, etc), because you really can’t get to a state where `session.custom` doesn’t mean _anything_, so allowing scripting to “fake” that would just be more confusing.

It is important generally to recognize that access to the property tree wrappers is inherently going into a queue - operations from different threads could theoretically put things into that queue at different times, which _may_ account for any odd behavior you initially noticed.

---

<div class="post-metadata">

**Author:** ![jross2020](https://avatars.discourse-cdn.com/v4/letter/j/d26b3c/32.png) [@jross2020](https://forum.inductiveautomation.com/u/jross2020)\
**Post date:** [August 4, 2020, 4:11pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/9 "2020-08-04T16:11:09Z")

</div>

> [@paul-griffith](#):
>
> It is important generally to recognize that access to the property tree wrappers is inherently going into a queue - operations from different threads could theoretically put things into that queue at different times, which _may_ account for any odd behavior you initially noticed.

Might be, however during debug I had trimmed down the environment to a single perspective window with a single button, and was still getting odd behaviors, so I'd be leaning more towards the bug possibility. Let's see what you find. Thanks!

---

<div class="post-metadata">

**Author:** ![Carl.Gould](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/carl.gould/32/7262_2.png) [@Carl.Gould](https://forum.inductiveautomation.com/u/Carl.Gould)\
**Post date:** [January 24, 2022, 5:12pm UTC](https://forum.inductiveautomation.com/t/bug-16904-behavior-of-perspective-custom-properties-vs-pj-ython-data-structures/37295/10 "2022-01-24T17:12:44Z")

</div>

Hi there. Under the category of “better late than never” - we believe this has been fixed. Please let us know if you’re still experiencing this behavior in the latest version (8.1.14)
