Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Default contextStorage suddenly changed in nodes to another one #2954

Closed
5 tasks
michalk-k opened this issue Apr 25, 2021 · 1 comment
Closed
5 tasks

Default contextStorage suddenly changed in nodes to another one #2954

michalk-k opened this issue Apr 25, 2021 · 1 comment

Comments

@michalk-k
Copy link

michalk-k commented Apr 25, 2021

What are the steps to reproduce?

Since I'm cannot install clean system, steps below are rather my best guess and come from expertise based on findings described below

  1. Make sure contextStorage is set to default values (no additional methods)
  2. Create flow with Change node. In this node set some operation which involves flow variable
  3. Extend contextStorage with additional method, ie inFile: { module: "localfilesystem"} put as the first attribute of contextStorage (see below)
  4. restart NR, reload flow from Mobile/Tablet Support #1 and check if the flow variable in the Change node remains marked as "default". In my case it turned to be displayed as "inFile"

As for alternative

[{"id":"6e2ad02c.aa90e","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"6ad61007.8e9aa8","type":"inject","z":"6e2ad02c.aa90e","name":"","repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":80,"wires":[["d8328be9.16e2f8"]]},{"id":"d8328be9.16e2f8","type":"change","z":"6e2ad02c.aa90e","name":"Config & init setup","rules":[{"t":"set","p":"message_content","pt":"flow","to":"{\"data\":{\"message\":\"Washing mashine has just finished after %s\",\"title\":\"Washing Mashine\",\"data\":{\"attachment\":{\"url\":\"https://www.freepnglogos.com/uploads/washing-machine-png/washing-machine-icon-download-png-and-ico-icon-easy-4.png\",\"content-type\":\"png\",\"hide-thumbnail\":false},\"apns_headers\":{\"apns-collapse-id\":\"WASHING_MACHINE\"},\"push\":{\"badge\":0,\"category\":\"WASHING_MACHINE\",\"sound\":{\"name\":\"default\",\"critical\":1,\"volume\":0.3}}}}}","tot":"json"},{"t":"set","p":"min_working_power","pt":"flow","to":"3","tot":"num"},{"t":"set","p":"max_idle_power","pt":"flow","to":"1.6","tot":"num"},{"t":"set","p":"idle_timeout","pt":"flow","to":"5000","tot":"num"},{"t":"set","p":"data","pt":"flow","to":"{\"date_start\":null,\"date_end\":null,\"work_time\":null,\"work_time_str\":null}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":80,"wires":[[]]}]
  1. import the code above
  2. Extend contextStorage with additional method, ie inFile: { module: "localfilesystem"} put as the first attribute of contextStorage (see below)
  3. restart NR, reload flow from Mobile/Tablet Support #1 and check if the flow variable in the Change node remains marked as "default". In my case it turned to be displayed as "inFile"

See the second post of this issue for another test-case which confirms it is not only "visual" issue.

What happens?

I just spotted, that with recent NR updates (unfortunately don't know with which one, I'm currently on v1.3.3), all env variable references used in Change and Switch nodes suddenly switched from default one (which is in-memory) to other one (which in my case is storage one, named inFile)

here is a snippet from my NR config

contextStorage: {
    inFile: { module: "localfilesystem"},
    default: { module: "memory" }
    },

Image below supports my finding that something is wrong: run-time variables are still from default category, while config of Change variable shows "inFile"

obrazek

After revising all flows, it seems all Change and Switch nodes are affected.

Guessing the reason I've changed the order in contextStorage object in configuration. It makes all flows, which weren't explicitly set to "inFile" back to "default":

contextStorage: {
    default: { module: "memory" },
    inFile: { module: "localfilesystem"}
    },

It seems that in recent NR something changed in how "default" is picked up from contextStorage object. I never changed the order before (I was using it in the form presented in OP since adding inFile to it). But NR changed how it interprets it.

Additional finding:
I've just checked, it affects drop list selector too incl value which is shown as set (see images below). It makes a risk that saving such node replace previous "default" value with unwanted/unexpected "inFile" value.

For:

contextStorage: {
    default: { module: "memory" },
    inFile: { module: "localfilesystem"}
    },

obrazek

For

contextStorage: {
	inFile: { module: "localfilesystem"},
    default: { module: "memory" }
    },

obrazek

What do you expect to happen?

Default contextStorage available in to be set nodes remains unchanged regardless order of attributes defined in contextStorage.

Please tell us about your environment:

  • Node-RED version: 1.3.3
  • Node.js version:
  • npm version:
  • Platform/OS: HassOS/HomeAssistant official addon
  • Browser: Firefox/Chrome
@michalk-k
Copy link
Author

Additional test:

Performed on flow:

[{"id":"6e2ad02c.aa90e","type":"tab","label":"Flow 5","disabled":false,"info":""},{"id":"6ad61007.8e9aa8","type":"inject","z":"6e2ad02c.aa90e","name":"","repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":80,"wires":[["d8328be9.16e2f8"]]},{"id":"d8328be9.16e2f8","type":"change","z":"6e2ad02c.aa90e","name":"Config & init setup","rules":[{"t":"set","p":"message_content","pt":"flow","to":"{\"data\":{\"message\":\"Washing mashine has just finished after %s\",\"title\":\"Washing Mashine\",\"data\":{\"attachment\":{\"url\":\"https://www.freepnglogos.com/uploads/washing-machine-png/washing-machine-icon-download-png-and-ico-icon-easy-4.png\",\"content-type\":\"png\",\"hide-thumbnail\":false},\"apns_headers\":{\"apns-collapse-id\":\"WASHING_MACHINE\"},\"push\":{\"badge\":0,\"category\":\"WASHING_MACHINE\",\"sound\":{\"name\":\"default\",\"critical\":1,\"volume\":0.3}}}}}","tot":"json"},{"t":"set","p":"min_working_power","pt":"flow","to":"3","tot":"num"},{"t":"set","p":"max_idle_power","pt":"flow","to":"1.6","tot":"num"},{"t":"set","p":"idle_timeout","pt":"flow","to":"5000","tot":"num"},{"t":"set","p":"data","pt":"flow","to":"{\"date_start\":null,\"date_end\":null,\"work_time\":null,\"work_time_str\":null}","tot":"json"}],"action":"","property":"","from":"","to":"","reg":false,"x":370,"y":80,"wires":[[]]}]

After changing configuration
from

contextStorage: {
    default: { module: "memory" },
    inFile: { module: "localfilesystem"}
    },

to

contextStorage: {
	inFile: { module: "localfilesystem"},
    default: { module: "memory" }
    },

flows remains unchanged functional wise. Of course as long as we can trust that what is exported (using NR export feature) is being executed.

however if I change anything in the node (ie its name), which raise requirement to save it, the code changes. Here is comparison of what changed in node source after node name changed:

left side: values after config change to inFile being first, default - second attribute of contextStorage

obrazek

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant