# Buggy code
async def train(request: Request):
    """Train a Rasa Model."""
    from rasa.train import train_async

    validate_request_body(
        request,
        "You must provide training data in the request body in order to "
        "train your model.",
    )

    rjs = request.json
    validate_request(rjs)

    # create a temporary directory to store config, domain and
    # training data
    temp_dir = tempfile.mkdtemp()

    config_path = os.path.join(temp_dir, "config.yml")
    dump_obj_as_str_to_file(config_path, rjs["config"])

    if "nlu" in rjs:
        nlu_path = os.path.join(temp_dir, "nlu.md")
        dump_obj_as_str_to_file(nlu_path, rjs["nlu"])

    if "stories" in rjs:
        stories_path = os.path.join(temp_dir, "stories.md")
        dump_obj_as_str_to_file(stories_path, rjs["stories"])

    domain_path = DEFAULT_DOMAIN_PATH
    if "domain" in rjs:
        domain_path = os.path.join(temp_dir, "domain.yml")
        dump_obj_as_str_to_file(domain_path, rjs["domain"])

    try:
        model_path = await train_async(
            domain=domain_path,
            config=config_path,
            training_files=temp_dir,
            output_path=rjs.get("out", DEFAULT_MODELS_PATH),
            force_training=rjs.get("force", False),
        )

        return await response.file(model_path)
    except Exception as e:
        logger.debug(traceback.format_exc())
        raise ErrorResponse(
            500,
            "TrainingError",
            "An unexpected error occurred during training. Error: {}".format(e),
        )


# 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
async def train(request: Request):
    """Train a Rasa Model."""
    from rasa.train import train_async

    validate_request_body(
        request,
        "You must provide training data in the request body in order to "
        "train your model.",
    )

    rjs = request.json
    validate_request(rjs)

    # create a temporary directory to store config, domain and
    # training data
    temp_dir = tempfile.mkdtemp()

    config_path = os.path.join(temp_dir, "config.yml")
    dump_obj_as_str_to_file(config_path, rjs["config"])

    if "nlu" in rjs:
        nlu_path = os.path.join(temp_dir, "nlu.md")
        dump_obj_as_str_to_file(nlu_path, rjs["nlu"])

    if "stories" in rjs:
        stories_path = os.path.join(temp_dir, "stories.md")
        dump_obj_as_str_to_file(stories_path, rjs["stories"])

    domain_path = DEFAULT_DOMAIN_PATH
    if "domain" in rjs:
        domain_path = os.path.join(temp_dir, "domain.yml")
        dump_obj_as_str_to_file(domain_path, rjs["domain"])

    try:
        model_path = await train_async(
            domain=domain_path,
            config=config_path,
            training_files=temp_dir,
            output_path=rjs.get("out", DEFAULT_MODELS_PATH),
            force_training=rjs.get("force", False),
        )
        return await response.file(model_path)
    except InvalidDomain as e:
        raise ErrorResponse(
            400,
            "InvalidDomainError",
            "Provided domain file is invalid. Error: {}".format(e),
        )
    except Exception as e:
        logger.debug(traceback.format_exc())
        raise ErrorResponse(
            500,
            "TrainingError",
            "An unexpected error occurred during training. Error: {}".format(e),
        )