Part 2: Parent context variable accessed in subflow’s first function node yields undefined?

The existing thread with the same topic got closed automatically so continuing it here...

Managed to make a minimal flow which can reproduce the issue on 2.2.2 and made a video of it. However, it still cannot be reproduced all the time...

I shared the video on my google drive.

The flow contains two subflows of which subflow 1 receives a msg.payload from an inject node and stores that payload in a flow context variable:

let b=0;
node.warn(msg.payload);
flow.set("test",msg.payload);
return msg;

Then it calls subflow 2 which contains a function to get the same variable set in its parent:

let a=1;
node.warn(flow.get("$parent.test"));
return msg;

When I first click the inject, the node.warn() in subflow 1 logs the payload received (true) on the debug pane and the node.warn() in subflow 2 logs the value (undefined) of the variable read from the parent context.

Then I simply change an unnecessary code line (changing let a=0 to let a=1) in the function of subflow 2 just to be able to trigger a deploy. After that, injecting a payload to subflow 1 results in logging the same value (true) by both subflows.

Here is the flow exported:

[
    {
        "id": "f70d4fc3.c71c38",
        "type": "subflow",
        "name": "Subflow 2",
        "info": "",
        "in": [
            {
                "x": 80,
                "y": 80,
                "wires": [
                    {
                        "id": "e7a1deed.3d9288"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 320,
                "y": 80,
                "wires": [
                    {
                        "id": "e7a1deed.3d9288",
                        "port": 0
                    }
                ]
            }
        ]
    },
    {
        "id": "e7a1deed.3d9288",
        "type": "function",
        "z": "f70d4fc3.c71c38",
        "name": "",
        "func": "let a=1;\nnode.warn(flow.get(\"$parent.test\"));\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "libs": [],
        "x": 200,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "70f7ac75.ea8e34",
        "type": "subflow",
        "name": "Subflow 1",
        "info": "",
        "in": [
            {
                "x": 80,
                "y": 80,
                "wires": [
                    {
                        "id": "48517af6.d85314"
                    }
                ]
            }
        ],
        "out": [
            {
                "x": 480,
                "y": 80,
                "wires": [
                    {
                        "id": "ab5276b6.32ea1",
                        "port": 0
                    }
                ]
            }
        ]
    },
    {
        "id": "48517af6.d85314",
        "type": "function",
        "z": "70f7ac75.ea8e34",
        "name": "",
        "func": "let b=0;\nnode.warn(msg.payload);\nflow.set(\"test\",msg.payload);\nreturn msg;",
        "outputs": 1,
        "noerr": 0,
        "initialize": "",
        "finalize": "",
        "x": 190,
        "y": 80,
        "wires": [
            [
                "ab5276b6.32ea1"
            ]
        ]
    },
    {
        "id": "ab5276b6.32ea1",
        "type": "subflow:f70d4fc3.c71c38",
        "z": "70f7ac75.ea8e34",
        "name": "",
        "env": [],
        "x": 360,
        "y": 80,
        "wires": [
            []
        ]
    },
    {
        "id": "aa2b5804.9cad4",
        "type": "subflow:70f7ac75.ea8e34",
        "z": "fb075204.b32578",
        "name": "",
        "env": [],
        "x": 340,
        "y": 540,
        "wires": [
            []
        ]
    },
    {
        "id": "ec2e7096.f0e618",
        "type": "inject",
        "z": "fb075204.b32578",
        "name": "",
        "props": [
            {
                "p": "payload"
            }
        ],
        "repeat": "",
        "crontab": "",
        "once": false,
        "onceDelay": "0",
        "topic": "",
        "payload": "true",
        "payloadType": "bool",
        "x": 170,
        "y": 540,
        "wires": [
            [
                "aa2b5804.9cad4"
            ]
        ]
    }
]

Please either stick to forum or Issue tracker.

Issue raised here: Parent context variable accessed in subflow’s first function node yields undefined · Issue #3485 · node-red/node-red · GitHub

Closing this thread to reduce duplication.