# Not able to set session attribute

**URL:** <https://community.gatling.io/t/not-able-to-set-session-attribute/2392>\
**Category:** Gatling (Open-Source)\
**Created:** [July 7, 2015, 11:32pm UTC](https://community.gatling.io/t/not-able-to-set-session-attribute/2392 "2015-07-07T23:32:24Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Akash\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Akash\_Agarwal](https://community.gatling.io/u/Akash_Agarwal)\
**Post date:** [July 7, 2015, 11:32pm UTC](https://community.gatling.io/t/not-able-to-set-session-attribute/2392/1 "2015-07-07T23:32:24Z")

</div>

Hi,

I am trying to execute a sequence of chains and setting a session attribute in between somewhere. The problem is this variable is not getting set correctly and I get an error saying **No attribute named ‘toUpdate’ is defined**. Here is the code

No attribute named ‘toUpdate’ is defined

scenario(“Test”).exec(postChain("/orders", Helper.generateRequestBody(order)))  
.exec(getChain("/orders", “${id}”))  
.exec((session: Session) =\> {

val jsonString = session(“object”).as[String]  
val pojo = Helper.generatePojo(jsonString, classOf[Order]).asInstanceOf[Order]  
pojo.setName(pojo.getName + “Updated”)  
val toUpdate = Helper.generateRequestBody(pojo)  
session.set(“toUpdate”, toUpdate)  
session  
}  
)  
.exec(putChain("/orders", “${id}”, “${toUpdate}”))

I want to do the chains in this sequence POST → GET → UPDATE → DELETE and need the toUpdate attribute for the PUT request . Any suggestions?

Thanks,  
Akash

---

<div class="post-metadata">

**Author:** ![Pierre\_DAL-PRA](https://avatars.discourse-cdn.com/v4/letter/p/ecccb3/32.png) [@Pierre\_DAL-PRA](https://community.gatling.io/u/Pierre_DAL-PRA)\
**Post date:** [July 8, 2015, 5:33am UTC](https://community.gatling.io/t/not-able-to-set-session-attribute/2392/2 "2015-07-08T05:33:59Z")

</div>

Hi Akash,

As stated in the documentation([http://gatling.io/docs/2.1.6/session/session\_api.html#setting-attributes](http://gatling.io/docs/2.1.6/session/session_api.html#setting-attributes)), Sessions are immutable and session.set(…) returns the modified session, which is discarded in your case.  
Simply remove the last “session” in your exec block and it’ll work.

Cheers,

Pierre

---

<div class="post-metadata">

**Author:** ![Akash\_Agarwal](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@Akash\_Agarwal](https://community.gatling.io/u/Akash_Agarwal)\
**Post date:** [July 8, 2015, 7:09am UTC](https://community.gatling.io/t/not-able-to-set-session-attribute/2392/3 "2015-07-08T07:09:32Z")

</div>

Works now ! Thanks a lot Pierre !
