I think I can reproduce this issue using just one line of JS code, but I still do not understand the real cause. These are the steps:
- Install
node-red-contrib-lower
. (Almost any other node could be used, but this one is easy.)
- Import this flow (based on the one posted by @nileio):
[{"id":"1c9112c4.636bfd","type":"subflow","name":"subflow","info":"","category":"","in":[{"x":220,"y":80,"wires":[{"id":"a73a7eda.92af5"}]}],"out":[{"x":510,"y":80,"wires":[{"id":"a73a7eda.92af5","port":0}]}],"env":[],"color":"#DEB887"},{"id":"a73a7eda.92af5","type":"change","z":"1c9112c4.636bfd","name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"$parent.somecontext","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":380,"y":80,"wires":[[]]},{"id":"f35176ad.2aeec","type":"lower-case","z":"1c9112c4.636bfd","name":"","x":380,"y":140,"wires":[[]]},{"id":"b105ba0c.0e5f","type":"inject","z":"275b6d65.ead67a","name":"inject #1","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":180,"y":80,"wires":[["75695b82.5772ac"]]},{"id":"75695b82.5772ac","type":"change","z":"275b6d65.ead67a","name":"","rules":[{"t":"set","p":"somecontext","pt":"flow","to":"test","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":80,"wires":[[]]},{"id":"50266c7d.cfbd84","type":"subflow:1c9112c4.636bfd","z":"275b6d65.ead67a","name":"","env":[],"x":385,"y":145,"wires":[["6a4563f.1df9e9c"]]},{"id":"17bdb382.6c814c","type":"inject","z":"275b6d65.ead67a","name":"inject #2","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":235,"y":145,"wires":[["50266c7d.cfbd84"]]},{"id":"6a4563f.1df9e9c","type":"debug","z":"275b6d65.ead67a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":545,"y":145,"wires":[]}]
- At this point, triggering
inject #2
should give undefined as the debug
output. If you trigger inject #1
, followed by inject #2
, the debug output should be "test" and continue that way for future triggers of inject #2
. (All this is to be expected.)
- Edit
lowercase.js
(generally found in ~/.node-red/node_modules/node-red-contrib-lower/lower/) by adding one line (the 5th):
module.exports = function(RED) {
function LowerCaseNode(config) {
RED.nodes.createNode(this,config);
var node = this;
var context = node.context();
this.on('input', function(msg) {
msg.payload = msg.payload.toLowerCase();
node.send(msg);
});
}
RED.nodes.registerType("lower-case",LowerCaseNode);
}
- Repeat step 3. There should be no change.
- Stop and restart NR.
- Triggering
inject #2
now produces no output from the subflow.
Once you have reached step 6, the only way I have found to restore normal behavior is to edit the subflow template to remove the lower-case
node AND restart NR.
I suspect that an instance of a node inside a subflow does not really have its own node context, at least not in the usual way, but I've reached the limit of my understanding/guesswork.