# Is this a bug? Flow variables behaving strangely!

**URL:** https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259
**Category:** General
**Tags:** function-node
**Created:** [3 January 2024 17:55 UTC](https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259 "2024-01-03T17:55:39Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![chrisofCCL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrisofccl/32/42442_2.png) [@chrisofCCL](https://discourse.nodered.org/u/chrisofCCL)
#### Post date: [3 January 2024 17:55 UTC](https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259/1 "2024-01-03T17:55:39Z")

</div>

I've been away from NR for a while, but I think I've found a bug in 3.1.3,unless I'm misunderstanding flow context. I'm setting a flow context variable and then changing the local variable that it's set to. When I subsequently query the flow variable, it has changed to the new value of the local variable, although the flow variable itself has not been updated. It's as though the flow variable is persistently locked to the local variable.

Flow is as follows. Run the top part first and then the second, to query the flow variable.

```auto
[{"id":"febcdd33f975086e","type":"inject","z":"9c9c90fc3298cc64","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":170,"y":480,"wires":[["2e43ef757cdf1f2a"]]},{"id":"f88c416331377eec","type":"debug","z":"9c9c90fc3298cc64","name":"debug 60","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":770,"y":500,"wires":[]},{"id":"2e43ef757cdf1f2a","type":"function","z":"9c9c90fc3298cc64","name":"testBug","func":"var nodeObj={'prop1': 123, 'prop2':'hello'};\n\nflow.set('f_nodeObj',nodeObj);\n\nnodeObj.prop1={'aNewProperty': 456};\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":500,"y":480,"wires":[["f88c416331377eec"]]},{"id":"cc3482a1fe192447","type":"inject","z":"9c9c90fc3298cc64","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"true","payloadType":"bool","x":150,"y":560,"wires":[["e3ec6809c69d972d"]]},{"id":"6f2b91cc9ba5d81b","type":"debug","z":"9c9c90fc3298cc64","name":"debug 61","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":750,"y":580,"wires":[]},{"id":"e3ec6809c69d972d","type":"function","z":"9c9c90fc3298cc64","name":"getFlow","func":"\nvar nodeObj=flow.get('f_nodeObj');\n\nmsg.payload=nodeObj;\n\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":480,"y":560,"wires":[["6f2b91cc9ba5d81b"]]}]

```

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 January 2024 18:04 UTC](https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259/2 "2024-01-03T18:04:19Z")

</div>

No, this is how JavaScript works.

You are storing a pointer to an object.

---

<div class="post-metadata">

### Author: ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)
#### Post date: [3 January 2024 18:06 UTC](https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259/3 "2024-01-03T18:06:15Z")

</div>

Some of the hundreds of similar threads:

- [Context flow strange behavior/bug? - #3 by Colin](https://discourse.nodered.org/t/context-flow-strange-behavior-bug/77056/3)
- [Context updated automatically? - #2 by knolleary](https://discourse.nodered.org/t/context-updated-automatically/75451/2)
- [Update one object in Global Context array - #4 by Steve-Mcl](https://discourse.nodered.org/t/update-one-object-in-global-context-array/36790/4)
- [NR Conundrum sett flow context changes global context - #2 by E1cid](https://discourse.nodered.org/t/nr-conundrum-sett-flow-context-changes-global-context/68955/2)

---

<div class="post-metadata">

### Author: ![chrisofCCL](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/chrisofccl/32/42442_2.png) [@chrisofCCL](https://discourse.nodered.org/u/chrisofCCL)
#### Post date: [3 January 2024 19:38 UTC](https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259/4 "2024-01-03T19:38:10Z")

</div>

Thanks Steve. In my real code the answer was simply to clone an outgoing msg by using node.send rather than return.

---

<div class="post-metadata">

### Author: ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)
#### Post date: [3 March 2024 19:38 UTC](https://discourse.nodered.org/t/is-this-a-bug-flow-variables-behaving-strangely/84259/5 "2024-03-03T19:38:59Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
