Removed variables in subflow remains in callers

Noticed some data can unexpectedly remain in a subflow node (caller) when removed in subflow itself (definition). Lets say you have a subflow with env variables A, B and C. Now make use of that subflow in a regular flow, setting these values. Later, you remove/modify some, for example now subflow has A, B and D. But caller still has C.

Perhaps this is intentional? In either case, it's code not visible in editor. You have to look for it in flows.json. Would it be possible to make this visible? Perhaps move it to custom env list (next tab)?

Do you have an example flow to help to understand better?

Sure. Can't just share a single flow, since this is a situation that occurs in combination of flow + subflow.

Snapshot 1 - steps:

  1. Create a subflow, add env variables A, B, C
  2. Use that subflow in a flow, set values to A, B, C
[
    {
        "id": "760dd5928d0a0761",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5233ec6f57c1cbae",
        "type": "subflow",
        "name": "Subflow 1",
        "info": "",
        "category": "",
        "in": [],
        "out": [],
        "env": [
            {
                "name": "A",
                "type": "str",
                "value": "a"
            },
            {
                "name": "B",
                "type": "str",
                "value": "b"
            },
            {
                "name": "C",
                "type": "str",
                "value": "c"
            }
        ],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "fb62af5babb05f0b",
        "type": "subflow:5233ec6f57c1cbae",
        "z": "760dd5928d0a0761",
        "name": "",
        "env": [
            {
                "name": "A",
                "value": "1",
                "type": "str"
            },
            {
                "name": "B",
                "value": "2",
                "type": "str"
            },
            {
                "name": "C",
                "value": "3",
                "type": "str"
            }
        ],
        "x": 180,
        "y": 100,
        "wires": []
    }
]

Snapshot 2 - steps:
4) Remove env variable C in subflow
5) Add env variable D in subflow
6) Set env variable D in calling flow
Result: Flow using subflow still has C in flows.json, but this isn't visible in editor (or I haven't found anywhere it is shown)

[
    {
        "id": "760dd5928d0a0761",
        "type": "tab",
        "label": "Flow 1",
        "disabled": false,
        "info": "",
        "env": []
    },
    {
        "id": "5233ec6f57c1cbae",
        "type": "subflow",
        "name": "Subflow 1",
        "info": "",
        "category": "",
        "in": [],
        "out": [],
        "env": [
            {
                "name": "A",
                "type": "str",
                "value": "a"
            },
            {
                "name": "B",
                "type": "str",
                "value": "b"
            },
            {
                "name": "D",
                "type": "str",
                "value": "d"
            }
        ],
        "meta": {},
        "color": "#DDAA99"
    },
    {
        "id": "fb62af5babb05f0b",
        "type": "subflow:5233ec6f57c1cbae",
        "z": "760dd5928d0a0761",
        "name": "",
        "env": [
            {
                "name": "A",
                "value": "1",
                "type": "str"
            },
            {
                "name": "B",
                "value": "2",
                "type": "str"
            },
            {
                "name": "D",
                "value": "4",
                "type": "str"
            },
            {
                "name": "C",
                "value": "3",
                "type": "str"
            }
        ],
        "x": 180,
        "y": 100,
        "wires": []
    }
]

It may be reproducable without all these steps, perhaps just make subflow (with a single env variable), set a value to that variable when using that subflow in a flow, then remove that env variable in the subflow.

Is this just a transient problem that exists when you go through a sequence of modifying flows, or can you come up with a flow that shows the problem after a node red restart?

Thanks. Haven't tried that yet, so it might be cleaned up on NR restart? Not sure if node red runs "restart" when I restart docker container? I will try and see.

I tried restart without that changing anything. Can restart in general clean up old junk in flows.json?

Also, I've noticed similar dead data in flows_cred.json. That is before I turned on encryption, so I don't bother with that content anymore.

It isn't necessarily bad that the env variables in flow lingers after being removed in subflow. For example if going back and forth and adding those again, it can be nice to keep the original setting everywhere. The main issue may be that it isn't visible anywhere in the editor.

Ok can reproduce.

When you remove C in the Subflow definition, the variable C of the node instance is added to its own environment. I don't know if this is intentional, @Steve-Mcl ?

@GogoVega your description looks different to the Op. Perhaps it's just your minimal description I am misreading?

Op stated "Flow using subflow still has C in flows.json, but this isn't visible in editor"

While it's not ideal, i don't think it is a problem that will affect operation (would need to check if env.C is still accessable.

It is still present because it has migrated to the node environment.

To help you understand, here are the screens of the different steps:

  1. Import the flow then open the subflow instance


  2. Remove the C variable from the Subflow definition

  3. Reopen the Subflow instance


As you can see in the last picture the C variable has been moved to its own environnement.

Ah ha, I see.

This may be an unintended side affect - I am not certain it is intended.
We will need Nick to cast a eye over it.

Would you or the OP be gracious enough to raise an issue please? (cross link the issue with this post please)

1 Like

By the way, there is one undo issue when editing the Subflow definition - the color is not updated for instances.

1 Like

Thanks, forgot to look at the separate env variables table.If it is moved there (by accident), then that makes sense it is still kept in the flow instance? But still it's not visible in the node definition in editor? If the future fix will remove it completely from the subflow definition, probably it will also be removed from all node instances?

The environment variable list contains:

  • the editor variables (properties tab)
  • the classic variables (environnement tab)

Since the instance contains a C variable that no longer exists in the Subflow definition, this variable is considered classic and is therefore included in the env. tab.

A possible behavior that Nick needs to validate is to remove this C variable for each instance.

1 Like