# Buggy code
def collect_templates(
    yml_templates: Dict[Text, List[Any]],
) -> Dict[Text, List[Dict[Text, Any]]]:
    """Go through the templates and make sure they are all in dict format"""
    templates = {}
    for template_key, template_variations in yml_templates.items():
        validated_variations = []
        if template_variations is None:
            raise InvalidDomain(
                "Utterance '{}' does not have any defined templates.".format(
                    template_key
                )
            )

        for t in template_variations:
            # templates can either directly be strings or a dict with
            # options we will always create a dict out of them
            if isinstance(t, str):
                validated_variations.append({"text": t})
            elif "text" not in t and "custom" not in t:
                raise InvalidDomain(
                    "Utter template '{}' needs to contain either "
                    "'- text: '  or '- custom: ' attribute to be a proper "
                    "template.".format(template_key)
                )
            else:
                validated_variations.append(t)

        templates[template_key] = validated_variations
    return templates


# Traceback (AttributeError)
Starting Rasa X in local mode... 🚀
Traceback (most recent call last):
File "/.../.venv/bin/rasa", line 12, in <module>
sys.exit(main())
File "/.../.venv/lib/python3.6/site-packages/rasa/__main__.py", line 70, in main
cmdline_arguments.func(cmdline_arguments)
File "/.../.venv/lib/python3.6/site-packages/rasa/cli/x.py", line 243, in rasa_x
local.main(args, project_path, args.data, token=rasa_x_token)
File "/.../.venv/lib/python3.6/site-packages/rasax/community/local.py", line 194, in main
session)
File "/.../.venv/lib/python3.6/site-packages/rasax/community/local.py", line 144, in _initialize_with_local_data
LOCAL_PROJECT_NAME,
File "/.../.venv/lib/python3.6/site-packages/rasax/community/api/initialise.py", line 170, in inject_domain
username=username)
File "/.../.venv/lib/python3.6/site-packages/rasax/community/services/projects_service.py", line 48, in store_domain
templates = _templates(domain, username, project_id)
File "/.../.venv/lib/python3.6/site-packages/rasax/community/services/projects_service.py", line 259, in _templates
for template, responses in templates.items() for response in responses
File "/.../.venv/lib/python3.6/site-packages/rasax/community/services/projects_service.py", line 259, in <listcomp>
for template, responses in templates.items() for response in responses
AttributeError: 'str' object has no attribute 'get'

# Fixed code
def collect_templates(
    yml_templates: Dict[Text, List[Any]],
) -> Dict[Text, List[Dict[Text, Any]]]:
    """Go through the templates and make sure they are all in dict format"""
    templates = {}
    for template_key, template_variations in yml_templates.items():
        validated_variations = []
        if template_variations is None:
            raise InvalidDomain(
                "Utterance '{}' does not have any defined templates.".format(
                    template_key
                )
            )

        for t in template_variations:
            # templates should be a dict with options
            if isinstance(t, str):
                logger.warning(
                    "Deprecated: Templates should not be strings anymore. "
                    "Utterance template '{}' should contain either '- text: ' or "
                    "'- custom: ' attribute to be a proper template.".format(
                        template_key
                    )
                )
                validated_variations.append({"text": t})
            elif "text" not in t and "custom" not in t:
                raise InvalidDomain(
                    "Utter template '{}' needs to contain either "
                    "'- text: ' or '- custom: ' attribute to be a proper "
                    "template.".format(template_key)
                )
            else:
                validated_variations.append(t)

        templates[template_key] = validated_variations
    return templates