# NodeRed clears context when switching projects

**URL:** <https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757>\
**Category:** General\
**Created:** [28 July 2022 16:14 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757 "2022-07-28T16:14:36Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![SSHIntoMe](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@SSHIntoMe](https://discourse.nodered.org/u/SSHIntoMe)\
**Post date:** [28 July 2022 16:14 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/1 "2022-07-28T16:14:36Z")

</div>

Is there any way to retain the context data written to "file", when switching between different projects.  
I uncheck the "Clear Context when switching projects" setting, however, Nodered physically deletes the context folder from my harddrive, whenever a new Project is opened.

The context is retained, when restarting the server, or the nodered service itself.

Software:  
Nodered v2.2.2

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 July 2022 16:20 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/2 "2022-07-28T16:20:50Z")

</div>

Hi @SSHIntoMe

that sounds like a bug to me. If the 'clear context' option is unchecked, then it shouldn't be clearing context.

Can you raise an issue on github?

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 July 2022 17:03 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/3 "2022-07-28T17:03:57Z")

</div>

Might it be worth upgrading to the latest node red?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 July 2022 17:04 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/4 "2022-07-28T17:04:22Z")

</div>

Nothing has changed in that area of the code in 3.0.

---

<div class="post-metadata">

**Author:** ![SSHIntoMe](https://avatars.discourse-cdn.com/v4/letter/s/77aa72/32.png) [@SSHIntoMe](https://discourse.nodered.org/u/SSHIntoMe)\
**Post date:** [28 July 2022 17:10 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/5 "2022-07-28T17:10:19Z")

</div>

The issue persists after updating to v3.0.1.

**Edit** :  
Nodered deletes all context related to the flow, but retains the global context, when switching between different projects. So as long as I use `global.get` and `global.set`, instead of `context.set` or `flow.set`, the flow works as intended.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 July 2022 19:46 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/6 "2022-07-28T19:46:05Z")

</div>

I've just reproduced it in 3.0.1 so I went back to 2.2.2 and then to 2.0.0 (which did not have the check box) and the issue is in both of them also.

Shortly after you switch to a new project, the folder for the flow variables in the context folder is deleted. I could identify which folder it was by going to the project folder and looking at the `id` in the json file of the flow.

One other thing, when you do uncheck the checkbox it does not remain unchecked.

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [28 July 2022 20:07 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/7 "2022-07-28T20:07:35Z")

</div>

Just to repeat what I said on GitHub - 2.0.0 does _not_ contain this issue because 2.0.0 did not give you the option to have context maintained when switching projects - it would always clear context as that was the well-defined and intended behaviour.

The issue here is whether the newly added feature to disable the clearing of context is being properly honoured in the File Context plugin.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 July 2022 20:11 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/8 "2022-07-28T20:11:44Z")

</div>

I only went back to 2.0.0 to see about how far back the issue was. It does exist in V2.2.2 which does have the checkbox.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [28 July 2022 20:18 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/9 "2022-07-28T20:18:55Z")

</div>

@knolleary Ok it was introduced in v2.2.0, I checked 2.1.6 and it is not there but appears in 2.2.0

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [26 September 2022 20:19 UTC](https://discourse.nodered.org/t/nodered-clears-context-when-switching-projects/65757/10 "2022-09-26T20:19:48Z")

</div>

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