Config node has no properties on the server-side

Hi folks,

Have been implemented quite a number of config nodes in the past withouth problems, but now it fails. Must be something stupid, but I don't see what I am doing wrong. So it would be nice if somebody with a fresh pair of eyes can have a look at it.

  1. The html file of the config node is quite simple:
    <script type="text/html" data-template-name="tensorflowObjDetConfig">
       <div class="form-row">
           <label for="node-config-input-someProperty"><i class="fa fa-file-image-o"></i> Some proper</label>
           <input type="text" id="node-config-input-someProperty">
       </div>
    </script>
    
    <script type="text/javascript">
       RED.nodes.registerType('tensorflowObjDetConfig',{
         category: 'config',
         color: '#ff758d',
         defaults: {
             someProperty: {value:""}
         },   
    </script>
    
  2. And this is the js file of the config node:
     module.exports = function(RED) {
       var settings = RED.settings;
       function TensorFlowObjDetConfig(config) {
       }
    
       RED.nodes.registerType("tensorflowObjDetConfig",TensorFlowObjDetConfig);
    }
    
  3. This config node is being used in the html file of my custom node:
    <script type="text/html" data-template-name="tensorflowObjDet">
       <div class="form-row">
         <label for="node-input-tensorflowConfig"><i class="fa fa-cog"></i> Model</label>
         <input type="text" id="node-input-tensorflowConfig">
       </div>
    </script>
    
    <script type="text/javascript">
        RED.nodes.registerType('tensorflowObjDet', {
            ...
            defaults: {
               tensorflowConfig: {value:"", type: "tensorflowObjDetConfig"}
            },
            ...
         }
     });
    </script>
    

At first sight this seemed to be working fine. The input of that config node screen is persisted on the server (after Deploy). Because when I open an extra flow editor client browser session, the same data appears in the config node screen in the second client.

And the tensorflowConfig contains (on the server side) the id of the selected config node. So far so good.

But when I try to get (on the server side) the config node corresponding to that id:

if (node.tensorflowConfig) {
   var tensorflowConfigNode = RED.nodes.getNode(node.tensorflowConfig);
}

Then I get an empty config node instance, i.e. all the properties that I have entered in the config node screen are empty ;-(

You can see this also on the server side in the list of active nodes:

Not sure if this exception in the startup log is related to this:

TypeError: Cannot read properties of undefined (reading 'padEnd')
    at Flow.start (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/Flow.js:254:62)
    at Object.start [as startFlows] (/usr/lib/node_modules/node-red/node_modules/@node-red/runtime/lib/flows/index.js:394:33)

Thanks!!!
Bart

Hi @BartButenaers

You are missing the call to RED.nodes.createNode(this,config) inside the TensorFlowObjDetConfig function.

Even with that, the node in the runtime doesn't automatically get the config properties assigned to it - it's up to you to pull out whatever values from config you want to store on the node object directly and do so.

Hi @knolleary,
How could I have missed that...
Thanks for reviewing my code snippets!!!!!!!

1 Like

For anybody else making ever the same stupid mistake as me, I will write down here the code for Nick' solution...

When you change the js file of the config node to this:

 module.exports = function(RED) {
    var settings = RED.settings;

    function TensorFlowObjDetConfig(config) {
        RED.nodes.createNode(this,config);
        this.someProperty = config.someProperty;
    }

    RED.nodes.registerType("tensorflowObjDetConfig",TensorFlowObjDetConfig);
}

Then you will see the someProperty appearing in the node config instance:
image

1 Like

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