Possible bug Joining environment variables in typedInput

I thought it was possible to joining env vars in subflows but I am doing something wrong here.
I have checked out this thread: https://discourse.nodered.org/t/using-subflow-environment-variable-to-set-mqtt-topic/15331/8
Can anyone please have a look on my flow and tell me what I am doing wrong? Running Node-RED 3.1.0. Thanks in advance.

[{"id":"0ded66e5737053d9","type":"subflow","name":"Testing variables","info":"","category":"","in":[],"out":[],"env":[{"name":"TestVar","type":"str","value":"Hello"},{"name":"TestVarTwo","type":"env","value":"${TestVar}/there"}],"meta":{},"color":"#DDAA99"},{"id":"33b13892f850970e","type":"template","z":"0ded66e5737053d9","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Testing: {{env.TestVar}}","output":"str","x":360,"y":120,"wires":[["6fcc4ac59b03604c"]]},{"id":"0cec4ca1af413cef","type":"inject","z":"0ded66e5737053d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":210,"y":120,"wires":[["33b13892f850970e"]]},{"id":"6fcc4ac59b03604c","type":"debug","z":"0ded66e5737053d9","name":"debug 5","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":120,"wires":[]},{"id":"f31a6af5a11e30fe","type":"template","z":"0ded66e5737053d9","name":"","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"Testing: {{{env.TestVarTwo}}}","output":"str","x":360,"y":240,"wires":[["51964b64705566b5"]]},{"id":"c19f3ec0f7961bf3","type":"inject","z":"0ded66e5737053d9","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":true,"onceDelay":"2","topic":"","payload":"","payloadType":"date","x":210,"y":240,"wires":[["f31a6af5a11e30fe"]]},{"id":"51964b64705566b5","type":"debug","z":"0ded66e5737053d9","name":"debug 6","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":500,"y":240,"wires":[]},{"id":"b4896dcb7005690c","type":"comment","z":"0ded66e5737053d9","name":"Working:","info":"","x":180,"y":80,"wires":[]},{"id":"6e58914ffb2e3286","type":"comment","z":"0ded66e5737053d9","name":"Data from TestVar is not fetched:","info":"","x":250,"y":200,"wires":[]},{"id":"3ca4a95c5435471c","type":"tab","label":"Test","disabled":false,"info":"","env":[]},{"id":"d162577bafac2043","type":"subflow:0ded66e5737053d9","z":"3ca4a95c5435471c","name":"","x":180,"y":80,"wires":[]}]

Interersting...

Node RED: 3.1.0
Node : 18.12.0

image

Node RED: 3.0.2
Node : 18.14.0

image

If others also see this - might be worth raising an issue
Issues Ā· node-red/node-red (github.com)

1 Like

It looks like it could be a regression in node-red 3.1.0. I am surprised this is not caught in a test (fairly certain this has unit tests)

The way env vars are evaluated were changed in 3.1.0 (for supporting async JSONata) and this might be a side effect.

It may also be that in v3.0.2 that this was an unintended kind of thing (and why there is no test failure) and thus v3.1.0 has fixed it? (Speculation)

Please raise an issue so it can be investigated.

To save anyone loading the flow, the OP is specifying an env var value then using it in the very next row.

image

And while the docs state:

Using the TypedInput widget

Within the editor, the TypedInput widget can offer ā€˜environment variableā€™ as a type. When this type is selected, its value will be evaluated as follows:

  • if there is no ${} present, uses the whole value as the name of the environment variable. For example, "FOO" will be replaced with the value of process.env.FOO
  • if ${} is present, it will substitute the corresponding environment variable into the result: For example, given the value "Hello ${FOO}" and the env var FOO is set to World, this results in the value "Hello World"

I am hesitant to call it a bug (as env vars are typically used by the inner nodes) it does appear to be a change of behaviour - something we try to avoid.

Possible bug Joining environment variables in typedInput Ā· Issue #4379 Ā· node-red/node-red (github.com)

3 Likes

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