Is this a bug? Flow variables behaving strangely!

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.

[{"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"]]}]

No, this is how JavaScript works.

You are storing a pointer to an object.

Some of the hundreds of similar threads:

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

1 Like

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