Rasa forms using one object during parallel sessions?

Hello, I’m using FormAction and write __init__ method in it to set some values there which I used later in the forms different functions.

When two users in parallel write message to the bot, both session is using one CustomFormAction object. When one session sets self.param1, different user session see this variable.

My question is: Is there one object shared to several parallel session or I’m doing something wrong?

class CustomFormAction(FormAction):

    def __init__(self):
        self.param1 = None
        self.param2 = None

    def name(self) -> Text:
        return "custom form"

Hello and welcome to the Forum!

To save user information, I would suggest using Slots.

class CustomFormAction(FormAction):

    def name(self):
        return "custom form"

    def run(self, dispatcher, tracker, domain):
        param1 = tracker.get_slot('param1')
        param2 = tracker.get_slot('param2')

If you need to use __init__, you can set param1 and param2 to dictionaries with keys being the user ID. You can get it with tracker['sender_id'].

Slots are great idea! Thanks you!

1 Like

Please mark the post as solution if it helped you :slight_smile:

And if you need more guidance don’t hesitate to ask!

It will test it tomorrow and if it will help, I will mark it as solution ^^

1 Like