# Sub Flow Context Variables - via. http - are not unique

**URL:** <https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975>\
**Category:** General\
**Created:** [25 February 2022 09:49 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975 "2022-02-25T09:49:38Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)\
**Post date:** [25 February 2022 09:49 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975/1 "2022-02-25T09:49:38Z")

</div>

Hi Everyone

I am aware that each sub flow instance is self contained container so its context variables are unique it. I have tested this and it works.

I have a strange challenge.

I connected a http in node to a subflow.

Within subflow i go flow.set("TESTVAL2","LEMON"). (pseudo code)

What i find is on subsequent calls of http request the flow context variable persists.

Is this the expected behavior ? as i would assume each instance of subflow - even if via. http will be unique.

Or am i not understanding something here.

Here is the calling flow :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/e/1e75d00ad74ecce7a7fff8e3f46ecec187ab8e6f.png)

And the subflow itself :

 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/9/3/93b7250288556ad905de98767f6aca9fbf09569b.png)

---

<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:** [25 February 2022 10:01 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975/2 "2022-02-25T10:01:57Z")

</div>

Each http request is being passed to the same instance of the subflow, so is accessing the same flow context.

---

<div class="post-metadata">

**Author:** ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)\
**Post date:** [25 February 2022 11:26 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975/3 "2022-02-25T11:26:01Z")

</div>

Thanks Nick.  
I managed to circumvent my current issue (we removed the use of flow context variable as it could be avoided).

But logically would it be correct ? Shouldn't each http request be an independent e2e run ?  
I am myself not sure. Both sides of arguments have merits.

---

<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:** [25 February 2022 11:37 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975/4 "2022-02-25T11:37:45Z")

</div>

> [@SandeepA](#):
>
> But logically would it be correct ? Shouldn't each http request be an independent e2e run ?  
> I am myself not sure. Both sides of arguments have merits.

Yes, they both have merits, but Node-RED doesn't do per-message context. If you want to associate state with an individual message, attach it to the message.

---

<div class="post-metadata">

**Author:** ![SandeepA](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/sandeepa/32/63225_2.png) [@SandeepA](https://discourse.nodered.org/u/SandeepA)\
**Post date:** [25 February 2022 11:42 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975/5 "2022-02-25T11:42:40Z")

</div>

This is what i did eventually cos i did not absolutely really need that context .  
Thanks . I have sorted this for now.

---

<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 April 2022 11:43 UTC](https://discourse.nodered.org/t/sub-flow-context-variables-via-http-are-not-unique/58975/6 "2022-04-26T11:43:12Z")

</div>

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