Storing variables

I was using class variables to store information instead of storing it in slots:

class BookForm(FormAction):

def __init__(self):
    self.user_name = None
    self.email = None

The reason I did not use slots was that I did not want to specifically ask for the “user_name” and “email”. I get “user_name” and “email” from other information that the user gives.

However, with multiple users testing, I discovered that the “self.user_name” and “self.email” were being shared between users. Is this supposed to happen? How can I isolate this variables to each client id? Is there any other way to store variables other than using slots?

Yes, that is the way it is supposed to work. The actions themselves aren’t supposed to store instance state. The action server doesn’t create a BookForm instance for each user, it is only registered once and created a single instance of it.

I think slots would be best practice here, but there is nothing stopping you from creating a non instance variable and map client id’s to your custom data.

my_custom_data = {}
class BookForm(FormAction):
        
            def run(self,dispatcher: CollectingDispatcher, 
                        tracker: Tracker, domain: Dict[Text, Any]) -> List[Dict[Text, Any]]:
                my_custom_data[tracker.sender_id] =  ....
                return []
1 Like

thank you!

How can I then set a slot as not mandatory, so that I can just use the slot as variable?

Slots aren’t mandatory unless you mean the required_slots method in the form action. You can use other slots in the same way as you would do with other custom actions by just retrieving them from the tracker.

1 Like