node-red icon indicating copy to clipboard operation
node-red copied to clipboard

Subflow loses flow variable when used within other subflow

Open wauswaus opened this issue 2 years ago • 1 comments

Current Behavior

A subflow (subflow 2) used in a subflow (subflow1) loses its flow variables when the flow that calls subflow 1 is changed and deployed. The changes on the calling flow do not effect the subflow 1 node and the deploy method used is 'modified nodes'.

Example flow:

[{"id":"3db299f362d37f80","type":"subflow","name":"Subflow 2","info":"","in":[{"x":100,"y":80,"wires":[{"id":"e83fa91f942987ac"}]}],"out":[]},{"id":"e83fa91f942987ac","type":"switch","z":"3db299f362d37f80","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"},{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":210,"y":80,"wires":[["7af1c2dc75319914"],["5ea17a5c69271d70"]]},{"id":"d23aef91fe97c870","type":"trigger","z":"3db299f362d37f80","name":"","op1":"loop start 1","op2":"loop 1","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":520,"y":80,"wires":[["a3c6a81b9e9efd37"]]},{"id":"5ea17a5c69271d70","type":"change","z":"3db299f362d37f80","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":160,"wires":[["d23aef91fe97c870"]]},{"id":"f40f9563ce818c50","type":"debug","z":"3db299f362d37f80","name":"debug 2","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":840,"y":80,"wires":[]},{"id":"7af1c2dc75319914","type":"change","z":"3db299f362d37f80","name":"flow var","rules":[{"t":"set","p":"var2","pt":"flow","to":"subflow 2","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":360,"y":80,"wires":[["d23aef91fe97c870"]]},{"id":"a3c6a81b9e9efd37","type":"change","z":"3db299f362d37f80","name":"flow var","rules":[{"t":"set","p":"payload","pt":"msg","to":"var2","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":680,"y":80,"wires":[["f40f9563ce818c50","d23aef91fe97c870"]]},{"id":"97ba453de8f41d3b","type":"subflow","name":"Subflow 1","info":"","in":[{"x":180,"y":180,"wires":[{"id":"dc97afe41450aef3"},{"id":"d607a346c8b6839c"}]}],"out":[]},{"id":"dc97afe41450aef3","type":"switch","z":"97ba453de8f41d3b","name":"","property":"payload","propertyType":"msg","rules":[{"t":"eq","v":"start","vt":"str"},{"t":"eq","v":"stop","vt":"str"}],"checkall":"true","repair":false,"outputs":2,"x":290,"y":180,"wires":[["9bc6c17616dcd578"],["96131439e93583c0"]]},{"id":"f0ded39662847fca","type":"trigger","z":"97ba453de8f41d3b","name":"","op1":"loop start 1","op2":"loop 1","op1type":"str","op2type":"str","duration":"2","extend":false,"overrideDelay":false,"units":"s","reset":"","bytopic":"all","topic":"topic","outputs":1,"x":600,"y":180,"wires":[["2b065a7ec226682a"]]},{"id":"96131439e93583c0","type":"change","z":"97ba453de8f41d3b","name":"","rules":[{"t":"set","p":"reset","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":260,"wires":[["f0ded39662847fca"]]},{"id":"31cd5dbe5ccc6a6e","type":"debug","z":"97ba453de8f41d3b","name":"debug 1","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":920,"y":180,"wires":[]},{"id":"9bc6c17616dcd578","type":"change","z":"97ba453de8f41d3b","name":"flow var","rules":[{"t":"set","p":"var1","pt":"flow","to":"subflow 1","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":180,"wires":[["f0ded39662847fca"]]},{"id":"2b065a7ec226682a","type":"change","z":"97ba453de8f41d3b","name":"flow var","rules":[{"t":"set","p":"payload","pt":"msg","to":"var1","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":760,"y":180,"wires":[["31cd5dbe5ccc6a6e","f0ded39662847fca"]]},{"id":"d607a346c8b6839c","type":"subflow:3db299f362d37f80","z":"97ba453de8f41d3b","name":"","x":300,"y":100,"wires":[]},{"id":"ccdc4f1f78201a08","type":"tab","label":"Flow 3","disabled":false,"info":"","env":[]},{"id":"435622b048e852ec","type":"subflow:97ba453de8f41d3b","z":"ccdc4f1f78201a08","name":"","x":340,"y":180,"wires":[]},{"id":"df5745a7835cbbf7","type":"inject","z":"ccdc4f1f78201a08","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"start","payloadType":"str","x":130,"y":160,"wires":[["435622b048e852ec"]]},{"id":"e26a69cc81d83dd2","type":"inject","z":"ccdc4f1f78201a08","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"stop","payloadType":"str","x":130,"y":200,"wires":[["435622b048e852ec"]]}]

This flow calls a subflow which calls another subflow. Each subflow writes a string to a flow variable and starts a loop that reads the flow var and sends its content to the debug window every 2 seconds. If this is started using the start inject button in the main flow, just make any change on the main flow, for instance add another inject node and deploy this using the 'modified nodes' method.

The values of subflow 2 then becomes unavailable. The working of subflow1 stays ok.

Expected Behavior

When changing something on main flow, this does not effect the flow vars of subflow2 called by subflow1

Steps To Reproduce

See above

Example flow

see above

Environment

  • Node-RED version: V3.0.2
  • Node.js version: ?
  • npm version: ?
  • Platform/OS: Home Assistant 2022.9.4, node red addon V13.3.2
  • Browser: Firefox 104.0.2

wauswaus avatar Sep 18 '22 08:09 wauswaus

Having the same issue:

Subflow1: image

Subflow 2: image

Flow: image

  • First inject sends a value 11.
  • Second inject writes that value into console.

If I make changes to the main flow and press the second inject it writes empty value into console. (it should write "11") image

If I use only one subflow everything works as expected: image

petrjaros avatar Sep 24 '22 13:09 petrjaros

Having the same issue:

@petrjaros

can you please post a working demo flow (containing minimum amount of nodes possible that demonstrates this error)

Steve-Mcl avatar Sep 29 '22 17:09 Steve-Mcl

A subflow (subflow 2) used in a subflow (subflow1) loses its flow variables when the flow that calls subflow 1 is changed and deployed. The changes on the calling flow do not effect the subflow 1 node and the deploy method used is 'modified nodes'.

I have imported your flow and can see this issue occuring.

For (our) reference...

  1. Import flow
  2. Click Start & monitor output... image
  3. Add a node and deploy
  4. Monitor debug output - debug node of subflow 2 has lost flow.var2 image

Steve-Mcl avatar Sep 29 '22 17:09 Steve-Mcl

@Steve-Mcl This may even have the same root cause as the one I reported since in that case it also turned out that during the deploy the context gets deleted in certain cases for whatever reasons: https://github.com/node-red/node-red/issues/3485#issuecomment-1175115070

r0ller avatar Oct 13 '22 11:10 r0ller

I was wondering if any progress was made on this ticket.

wauswaus avatar Jan 04 '23 09:01 wauswaus

Fixed via https://github.com/node-red/node-red/pull/4093 - will be in 3.1

knolleary avatar Mar 03 '23 18:03 knolleary