# Buggy code
def _import_child(
    cls, stack_properties: dict, parent_stack: "Stack"
) -> Optional["Stack"]:
    url = ""
    for event in parent_stack.events():
        if event.physical_id == stack_properties["StackId"] and event.properties:
            url = event.properties["TemplateURL"]
    if url.startswith(parent_stack.template.url_prefix()):
        # Template is part of the project, discovering path
        relative_path = url.replace(parent_stack.template.url_prefix(), "").lstrip("/")
        absolute_path = parent_stack.template.project_root / relative_path
    else:
        # Assuming template is remote to project and downloading it
        cfn_client = parent_stack.client
        tempate_body = cfn_client.get_template(StackName=stack_properties["StackId"])[
            "TemplateBody"
        ]
        path = parent_stack.template.project_root / Stack.REMOTE_TEMPLATE_PATH
        os.makedirs(path, exist_ok=True)
        fname = (
            "".join(
                random.choice(string.ascii_lowercase)
                for _ in range(16)  # nosec
            )
            + ".template"
        )
        absolute_path = path / fname
        if not absolute_path.exists():
            with open(absolute_path, "w") as fh:
                fh.write(tempate_body)
    template = Template(
        template_path=str(absolute_path),
        project_root=parent_stack.template.project_root,
        url=url,
    )
    stack = cls(
        parent_stack.region,
        stack_properties["StackId"],
        template,
        parent_stack.name,
        parent_stack.uuid,
    )
    stack.set_stack_properties(stack_properties)
    return stack


# Traceback (TypeError)
[ERROR  ] : TypeError write() argument must be str, not collections.OrderedDict
Traceback (most recent call last):
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_cli.py", line 66, in main
cli.run()
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_cli_core.py", line 228, in run
return getattr(command(), subcommand)(**args)
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_cli_modules/test.py", line 81, in run
terminal_printer.report_test_progress(stacker=test_definition)
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_tui.py", line 24, in report_test_progress
self._print_stack_tree(stack, buffer=self.buffer)
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_tui.py", line 37, in _print_stack_tree
if stack.descendants():
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_cfn/stack.py", line 495, in descendants
self._fetch_children()
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_cfn/stack.py", line 481, in _fetch_children
stack_obj = Stack._import_child(stack, self)
File "/home/ags/venv/venv-taskcat/lib/python3.6/site-packages/taskcat/_cfn/stack.py", line 335, in _import_child
fh.write(tempate_body)
TypeError: write() argument must be str, not collections.OrderedDict

# Fixed code
def _import_child(  # pylint: disable=too-many-locals
    cls, stack_properties: dict, parent_stack: "Stack"
) -> Optional["Stack"]:
    url = ""
    for event in parent_stack.events():
        if event.physical_id == stack_properties["StackId"] and event.properties:
            url = event.properties["TemplateURL"]
    if url.startswith(parent_stack.template.url_prefix()):
        # Template is part of the project, discovering path
        relative_path = url.replace(parent_stack.template.url_prefix(), "").lstrip("/")
        absolute_path = parent_stack.template.project_root / relative_path
    else:
        try:
            # Assuming template is remote to project and downloading it
            cfn_client = parent_stack.client
            tempate_body = cfn_client.get_template(
                StackName=stack_properties["StackId"]
            )["TemplateBody"]
            path = parent_stack.template.project_root / Stack.REMOTE_TEMPLATE_PATH
            os.makedirs(path, exist_ok=True)
            fname = (
                "".join(
                    random.choice(string.ascii_lowercase)  # nosec
                    for _ in range(16)
                )
                + ".template"
            )
            absolute_path = path / fname
            template_str = ordered_dump(tempate_body, Dumper=yaml.SafeDumper)
            if not absolute_path.exists():
                with open(absolute_path, "w") as fh:
                    fh.write(template_str)
        except Exception as e:  # pylint: disable=broad-except
            LOG.warning(
                f"Failed to attach child stack {stack_properties['StackId']} {str(e)}"
            )
            LOG.debug("traceback", exc_info=True)
            return None
    template = Template(
        template_path=str(absolute_path),
        project_root=parent_stack.template.project_root,
        url=url,
    )
    stack = cls(
        parent_stack.region,
        stack_properties["StackId"],
        template,
        parent_stack.name,
        parent_stack.uuid,
    )
    stack.set_stack_properties(stack_properties)
    return stack