Context.get stoped working

#1

Hi All,

I had used a simple function to check if the value of the water tank had changed before sending a slack notification. was all working then one day started sending it every time like it was not saving the value.
I tried changing the variable name from ('Tank1') to (TankOne') deployed and all working again.
Any ideas why, I do get many messages is there a limit to how many times you can save a context variable?

var tank1=context.get('tankOne') ||0;
if (msg.payload != tank1){
context.set('tankOne',msg.payload);
return msg;
}else{
msg.payload="Same";
return msg
}

I did debugs and it had stoped sending "Same" and always sent on the msg.payload.

0 Likes

#2

What change did you make to the flow just before the issue occurred?

0 Likes

#3

Try this and see from the debug pane what is going on

var tank1=context.get('tankOne') ||0;
node.warn("payload: " + msg.payload +"tank1: " + tank1);
if (msg.payload != tank1){
  node.warn("Different");
  context.set('tankOne',msg.payload);
  return msg;
}else{
  node.warn("Same");
  msg.payload="Same";
  return msg
}
0 Likes

#4

@zenofmud I think I had moved a flow from that worspace to another tab (sorry if that terminology is not correct) via cut and paste then deploy. These nodes that modes were not part of this flow but were on the same tab.
I may have also removed the degbugs.

0 Likes

#5

Hi Colin, when I changed
tank1=context.get('tank1')

to

tank1=context.get('tankOne')

and the set it fixed it, as stated above but I don't know why it was broken or why changing a variable name would fix it.

I will try out the node.warn though, is it similar to a debug?

0 Likes

#6

It would be my guess that if everything was working and then you moved some flows and then it stopped working, something you moved was the root of your issue.

But since it is now working, I would not spend too much time on rying to figure out why if you can't recreate it.

0 Likes

#7

I would agree except they were unlelated and I didn't undo any of it to fix it which makes me think there is some sort or NodeRed bug around context variables.
Its about stability, the result was many people being spamed in slack and I would like to make sure it doesn't happen again. I could clearly prove before changing the variable name that I did a save and 5 seconds later when retrieving it, it was back to default.
I will try changing it back to that old variable name.

0 Likes

#8

Try it and see what it does.

0 Likes