Rasa FormAction triggers a "NoneType object is not iterable" error

Hi there, I’m following this post of yours: https://blog.rasa.com/building-contextual-assistants-with-rasa-formaction/ While trying to implement a very simple FormAction, and testing it with a sentence that is also included in the NLU, I get the NoneType object error. I can’t figure out why.

rasa2

rasa4

Any help is very appreciated. Thanks for taking some time to help me!

Here’s the error I get when debugging:

This is very strange, as RASA is correctly detecting the slot (threat_type: Flood)

For anyone having the same problem, I’ve found the solution:

unlike regular custom actions, FormActions need to return a list. So adding a return [ ] solved the problem.

Actually, only the ‘FormAction.submit’-method needs to return an iterable which can be used as an argument for list.extend, which is used in the FormAction’s ‘run’-method.

That is correct, I wasn’t clear enough, but yes, only the submit method needs to return an iterable. Thank you for clarifying!

This error means that python is trying to iterate over a None object. With Python, you can only iterate over an object if that object has a value. This is because iterable objects only have a next item which can be accessed if their value is not equal to None. If you try to iterate over a None object, you encounter the TypeError: ‘NoneType’ object is not iterable error.

For example, list.sort() only change the list but return None.

Python’s interpreter converted your code to pyc bytecode. The Python virtual machine processed the bytecode, it encountered a looping construct which said iterate over a variable containing None. The operation was performed by invoking the __iter__ method on the None. None has no __iter__ method defined, so Python’s virtual machine tells you what it sees: that NoneType has no __iter__ method.

Technically, you can avoid the NoneType exception by checking if a value is equal to None before you iterate over that value.