Cannot deactivate a form

Hi,

I want to deactivate a form from inside the slot validation but self.deactivate() seems not working.

This is my code:

 def validate_feed_edit(
        self,
        value: Text,
        dispatcher: CollectingDispatcher,
        tracker: Tracker,
        domain: Dict[Text, Any],
    ) -> Dict[Text, Any]:
        """Validate confirm value."""

        if value == "Edit Soreness":
            # requires to fill again the fields "feed_soreness", "feed_confirm" and "feed_edit"
            return {"feed_soreness": None, "feed_confirm": None, "feed_edit": None}
        elif value == "Edit Lesion Changes":
            # requires to fill again the fields "feed_change", "feed_confirm" and "feed_edit"
            return {"feed_change": None, "feed_confirm": None, "feed_edit": None}
        elif value == "Edit Overall Feedback":
            # requires to fill again the fields "feed_overall", "feed_confirm" and "feed_edit"
            return {"feed_overall": None, "feed_confirm": None, "feed_edit": None}
        elif value == "Abort Operation":
            # aborts all operations and sets all slots to None
            dispatcher.utter_message("Ok, no action will be done")
            return self.deactivate()

And this is the error that I get:

Traceback (most recent call last):
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask\app.py", line 2446, in wsgi_app
    response = self.full_dispatch_request()
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask\app.py", line 1951, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask_cors\extension.py", line 161, in wrapped_function
    return cors_after_request(app.make_response(f(*args, **kwargs)))
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask\app.py", line 1820, in handle_user_exception
    reraise(exc_type, exc_value, tb)
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask\_compat.py", line 39, in reraise
    raise value
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask\app.py", line 1949, in full_dispatch_request
    rv = self.dispatch_request()
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask\app.py", line 1935, in dispatch_request
    return self.view_functions[rule.endpoint](**req.view_args)
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\flask_cors\decorator.py", line 128, in wrapped_function
    resp = make_response(f(*args, **kwargs))
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\rasa_sdk\endpoint.py", line 66, in webhook
    response = executor.run(action_call)
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\rasa_sdk\executor.py", line 249, in run
    events = action(dispatcher, tracker, domain)
  File "c:\users\tizianolabruna\anaconda3\lib\site-packages\rasa_sdk\forms.py", line 554, in run
    events.extend(self.submit(dispatcher, temp_tracker, domain))
TypeError: 'NoneType' object is not iterable
127.0.0.1 - - [2019-12-11 15:52:09] "POST /webhook HTTP/1.1" 500 411 0.000000

Hello @tiziano,

It seems that you can no longer deactivate a form by returning self.deactivate() in the validate function anymore, even though the Rasa doc says you can:

You can also deactivate the form directly during this validation step (in case the slot is filled with something that you are certain can’t be handled) by returning self.deactivate()

Check this accepted answer to see if it can solve your problem: Restart conversation inside validation function

@Tanja What do you think about editing the Rasa document about this ?

@fuih Seems to be a good idea! Thanks for pointing it out. If you want you can go ahead and suggest an edit of the Forms page directly. (cc @erohmensing)

So, if I got it correctly, it’s not possible to deactivate a form from inside the validation?

The only way is to overwrite the request_next_slot function? It doesn’t really fit my issue…

@tiziano It’s the only way i know at the moment. Another way (still a little bit inefficient) is to assign a specific value for the slot (e.g: “invalid”) in your validate function, after that, the form will execute the submit function and you can check if the slot’s value is “invalid” then just don’t do anything (or utter a warning). The form will end without executing any action, which to the user it seems like the form is deactivate. But if you require the bot to ask for the slot again, then this approach will not work.

@Tanja I don’t really have an ideal solution for the problem so i won’t suggest an edit (unless if just deleting the wrong instruction is enough).

1 Like

Ok, I solved the issue by addying these lines inside request_next_slot:

message = (tracker.latest_message)['text']
if message == "Abort Operation":
        return self.deactivate()

Thank you @fuih

1 Like

Created an issue for updating the documentation Update docs: deactivating forms · Issue #4962 · RasaHQ/rasa · GitHub, we are going to take care of it as soon as possible.

Hi @Tanja,

Is the ongoing deactivate form issue fixed? One more thing, is it possible to implement counter in validation. I want to implement the use case wherein if consecutive 3 wrong values given as part of validation , it should deactivate the current form.