# \[IGN-1660\]PSA - Assigning values to a property in a script may drive you nuts

**URL:** <https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192>\
**Category:** Ignition\
**Tags:** perspective, scripting, ignition81\
**Created:** [July 11, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192 "2023-07-11T14:29:25Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 11, 2023, 2:29pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/1 "2023-07-11T14:29:25Z")

</div>

Hello folks,

This got me pulling the hair out of my head. I spent the last hour yelling at my screen while doing all sorts of tests and experiments.  
I think I got it now, but... try it yourself.  
Here's the json for a perspective view:

> ****
>
> ```json
> {
> "custom": {},
> "params": {
> "category_id": "",
> "family_id": "",
> "item_id": ""
> },
> "propConfig": {
> "custom.isFresh": {
> "access": "PRIVATE"
> },
> "params.category_id": {
> "paramDirection": "input",
> "persistent": true
> },
> "params.family_id": {
> "paramDirection": "input",
> "persistent": true
> },
> "params.item_id": {
> "paramDirection": "input",
> "persistent": true
> }
> },
> "props": {},
> "root": {
> "children": [
> {
> "meta": {
> "name": "Label"
> },
> "position": {
> "basis": "32px"
> },
> "props": {
> "text": "open your console, type something in the text field, then click the button."
> },
> "type": "ia.display.label"
> },
> {
> "meta": {
> "name": "TextField"
> },
> "position": {
> "basis": "32px"
> },
> "props": {
> "placeholder": "type something here",
> "text": "qwd"
> },
> "type": "ia.input.text-field"
> },
> {
> "custom": {
> "data": {
> "text": "qwd"
> }
> },
> "events": {
> "component": {
> "onActionPerformed": {
> "config": {
> "script": "\tdata \u003d self.custom.data\n\t\n\ttext \u003d self.getSibling(\"TextField\").props.text\n\tdata[\u0027text\u0027] \u003d text\n\t\n\tsystem.perspective.print(\u0027-\u0027*20)\n\tsystem.perspective.print(\"text: {}\".format(text))\n\tsystem.perspective.print(\"data[\u0027text\u0027]: {}\".format(data[\u0027text\u0027]))"
> },
> "scope": "G",
> "type": "script"
> }
> }
> },
> "meta": {
> "name": "Button"
> },
> "position": {
> "basis": "34px"
> },
> "type": "ia.input.button"
> },
> {
> "meta": {
> "name": "Label_0"
> },
> "position": {
> "basis": "32px"
> },
> "props": {
> "text": "now check the code on the button..."
> },
> "type": "ia.display.label"
> }
> ],
> "meta": {
> "name": "root"
> },
> "props": {
> "direction": "column",
> "style": {
> "gap": "10px",
> "padding": "15px"
> }
> },
> "type": "ia.container.flex"
> }
> }
> 
> ```

Here's a quick summary:  
There's a button. There's a `data` custom property.  
The button has code on `onActionPerformed` as follow:

```python
data = self.custom.data

text = self.getSibling("TextField").props.text
data['text'] = text

system.perspective.print('-'*20)
system.perspective.print("text: {}".format(text))
system.perspective.print("data['text']: {}".format(data['text']))

```

The text field is only there to provide a way to change the value  
Simple, right ? wrong:

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/5/d/5de5d3a632fddc9c6afdbed5cf480e2dc792382c.png)

I'm guessing the printing happens before the property actually gets its value and since `data` is just a reference to that property, the old value is the one that gets printed.  
It would make sense, but damn did it trip me up !

If it's not that, then I'll take the whatever explanation you might have.

Anyway, if you ever find yourself in this situation - keep calm, declare another variable and use this one instead.

---

<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:** [July 11, 2023, 2:38pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/2 "2023-07-11T14:38:27Z")

</div>

IIUC, writes to Perspective properties are serialized by a queue somewhere. Not sure of the details, but it explains the behavior you are seeing.

---

<div class="post-metadata">

**Author:** ![victordcq](https://avatars.discourse-cdn.com/v4/letter/v/f6c823/32.png) [@victordcq](https://forum.inductiveautomation.com/u/victordcq)\
**Post date:** [July 11, 2023, 2:40pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/3 "2023-07-11T14:40:17Z")

</div>

im afread it will get more complicated... look at this

regrabbing the self.custom (dataRe) gives the coorrect value while data still is wrong

 ![image](https://us1.discourse-cdn.com/inductiveautomation/original/3X/8/1/815bc460bde2f619eea363475d3d32d24d59c8cb.png)

---

<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:** [July 11, 2023, 2:42pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/4 "2023-07-11T14:42:52Z")

</div>

> [@pascal.fragnoud](#):
>
> `data = self.custom.data`

Among other things, basically, don't do this. You're capturing the 'property tree' wrapper housed at `self.custom.data` in your script. Mutations are primarily forwarded to the actual backing store (because that's what matters, and what syncs to the frontend) and there's a longstanding bug where the local instance you have _doesn't_ reflect those updates correctly. It's mostly been a nuisance bug because the typical pattern (referring to component props fully qualified all the time) avoids it.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [July 11, 2023, 2:48pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/5 "2023-07-11T14:48:47Z")

</div>

> [@paul-griffith](#):
>
> there's a longstanding bug where the local instance you have _doesn't_ reflect those updates correctly

Man we run into this at least once or twice a week and it's super frustrating.

It's good to know we can "work around" this by using a fully qualified path, but sometimes those fully qualified paths look long and ugly.

---

<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:** [July 11, 2023, 2:59pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/6 "2023-07-11T14:59:11Z")

</div>

Yeah, I've bumped the internal ticket a bit in priority.

---

<div class="post-metadata">

**Author:** ![Felipe\_CRM](https://avatars.discourse-cdn.com/v4/letter/f/dfb087/32.png) [@Felipe\_CRM](https://forum.inductiveautomation.com/u/Felipe_CRM)\
**Post date:** [July 11, 2023, 3:10pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/7 "2023-07-11T15:10:04Z")

</div>

> [@Matthew.gaitan](#):
>
> sometimes those fully qualified paths look long and ugly.

Not only that, but now if you move anything around, you have to remember to update the path in multiple places within your script. Ctrl-F can help with that I guess but is not my favorite way

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 11, 2023, 3:10pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/8 "2023-07-11T15:10:17Z")

</div>

Yea okay that makes sense, and explains the weirdness exposed in @victordcq 's post

---

<div class="post-metadata">

**Author:** ![lrose](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/lrose/32/62724_2.png) [@lrose](https://forum.inductiveautomation.com/u/lrose)\
**Post date:** [July 11, 2023, 3:15pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/9 "2023-07-11T15:15:43Z")

</div>

> [@Matthew.gaitan](#):
>
> week and it's super frustrating

What's the term for "more than" super frustrating.

---

<div class="post-metadata">

**Author:** ![Matthew.gaitan](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@Matthew.gaitan](https://forum.inductiveautomation.com/u/Matthew.gaitan)\
**Post date:** [July 11, 2023, 3:26pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/10 "2023-07-11T15:26:07Z")

</div>

infuriating? ha

I will admit I get angry when I'm like "why the hell isn't this working"

---

<div class="post-metadata">

**Author:** ![pascal.fragnoud](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pascal.fragnoud/32/24728_2.png) [@pascal.fragnoud](https://forum.inductiveautomation.com/u/pascal.fragnoud)\
**Post date:** [July 11, 2023, 3:31pm UTC](https://forum.inductiveautomation.com/t/ign-1660-psa-assigning-values-to-a-property-in-a-script-may-drive-you-nuts/76192/11 "2023-07-11T15:31:37Z")

</div>

Imagine my face when I was doing

```python
a = b
return a == b

```

and it was returning `False`
