Subflow environment variables issue (_info, _type)

Hi,
I created simple subflow with one input, and one output.
Subflow has 3 properties: unit_test, unit_type, unit_tell. All of them are dropdowns with two options and string values.
Inside subflow there are function, that reads environment variables:

msg.env = [ env.get("unit_test"), env.get("unit_type"), env.get("unit_tell") ];
return msg;

On my flow, at subflow output I got this: ["opt1",null,"asdf"]

It means, that env.get("unit_type") always return null.
I tested this on multiple PCs and there is always this problem.
What wrong with "unit_type"?

Node-red version: 1.0.6
Nodes to test:

[{"id":"818111e.14a84f","type":"subflow","name":"test","info":"","category":"","in":[{"x":600,"y":320,"wires":[{"id":"aac98841.4feec8"}]}],"out":[{"x":880,"y":320,"wires":[{"id":"aac98841.4feec8","port":0}]}],"env":[{"name":"unit_test","type":"str","value":"opt1","ui":{"icon":"font-awesome/fa-arrow-circle-down","label":{"en-US":"Unit test"},"type":"select","opts":{"opts":[{"l":{"en-US":"opt1"},"v":"opt1"},{"l":{"en-US":"opt2"},"v":"opt2"}]}}},{"name":"unit_type","type":"str","value":"aaa","ui":{"icon":"font-awesome/fa-align-left","label":{"en-US":"Unit type"},"type":"select","opts":{"opts":[{"l":{"en-US":"aaa"},"v":"aaa"},{"l":{"en-US":"bbb"},"v":"bbb"}]}}},{"name":"unit_tell","type":"str","value":"asdf","ui":{"icon":"font-awesome/fa-compass","label":{"en-US":"Unit tell"},"type":"select","opts":{"opts":[{"l":{"en-US":"asdf"},"v":"asdf"},{"l":{"en-US":"qwer"},"v":"qwer"}]}}}],"color":"#DDAA99"},{"id":"aac98841.4feec8","type":"function","z":"818111e.14a84f","name":"","func":"msg.env = [ env.get(\"unit_test\"), env.get(\"unit_type\"), env.get(\"unit_tell\") ];\nreturn msg;","outputs":1,"noerr":0,"x":730,"y":320,"wires":[[]]},{"id":"259922d3.db2c6e","type":"debug","z":"f31cfc67.f14fb","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":830,"y":1840,"wires":[]},{"id":"a85acf85.0a113","type":"subflow:818111e.14a84f","z":"f31cfc67.f14fb","name":"","env":[{"name":"unit_type","value":"bbb","type":"str"}],"x":660,"y":1840,"wires":[["259922d3.db2c6e"]]},{"id":"555ec225.0c57bc","type":"inject","z":"f31cfc67.f14fb","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":480,"y":1840,"wires":[["a85acf85.0a113"]]}]

This is really strange. I see the same thing when importing your flow. Everything seems right. It’s just like it wasn’t there :thinking:
maybe @dceejay or @knolleary can have a look as this indeed looks like a bug unless we are booth missing something obvious here, which could be as i only had one cup of coffee so far :coffee: .

1 Like

Looks like, its not bug :thinking:

I found this:

node-red-master\packages\node_modules\@node-red\runtime\lib\nodes\flows\Subflow.js

    /**
     * Get environment variable of subflow
     * @param {String}   name   name of env var
     * @return {Object}  val    value of env var
     */
    getSetting(name) {
        this.trace("getSetting:"+name);
        if (!/^\$parent\./.test(name)) {
            var env = this.env;
            var is_info = name.endsWith("_info");
            var is_type = name.endsWith("_type");
            var ename = (is_info || is_type) ? name.substring(0, name.length -5) : name; // 5 = length of "_info"/"_type"

Using "*_info" as parameter name leads to the same behavior.

2 Likes

Hmm, yes - that is an unfortunate naming collision. We need to fix that to reduce the chances of a clash with the internal property names.

So yes, I would call it a bug on the basis that you had every right to expect your flow to work and it didn't because of an internal implementation detail.

2 Likes

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