# Buggy code
def create_version(
    model_name,
    deployemnt_uri=None,
    version_id=None,
    runtime_version=None,
    python_version=None,
    version=None,
    replace_existing=False,
    wait_interval=30,
    version_name_output_path="/tmp/kfp/output/ml_engine/version_name.txt",
    version_object_output_path="/tmp/kfp/output/ml_engine/version.json",
):
    """Creates a MLEngine version and wait for the operation to be done.

    Args:
        model_name (str): required, the name of the parent model.
        deployment_uri (str): optional, the Google Cloud Storage location of
            the trained model used to create the version.
        version_id (str): optional, the user provided short name of
            the version. If it is not provided, the operation uses a random name.
        runtime_version (str): optinal, the Cloud ML Engine runtime version
            to use for this deployment. If not set, Cloud ML Engine uses
            the default stable version, 1.0.
        python_version (str): optinal, the version of Python used in prediction.
            If not set, the default version is '2.7'. Python '3.5' is available
            when runtimeVersion is set to '1.4' and above. Python '2.7' works
            with all supported runtime versions.
        version (str): optional, the payload of the new version.
        replace_existing (boolean): boolean flag indicates whether to replace
            existing version in case of conflict.
        wait_interval (int): the interval to wait for a long running operation.
    """
    if not version:
        version = {}
    if deployemnt_uri:
        version["deploymentUri"] = deployemnt_uri
    if version_id:
        version["name"] = version_id
    if runtime_version:
        version["runtimeVersion"] = runtime_version
    if python_version:
        version["pythonVersion"] = python_version

    return CreateVersionOp(
        model_name,
        version,
        replace_existing,
        wait_interval,
        version_name_output_path=version_name_output_path,
        version_object_output_path=version_object_output_path,
    ).execute_and_wait()


# Traceback (TypeError)
Traceback (most recent call last):
File "/usr/local/lib/python2.7/runpy.py", line 174, in _run_module_as_main
"__main__", fname, loader, pkg_name)
File "/usr/local/lib/python2.7/runpy.py", line 72, in _run_code
exec code in run_globals
File "/ml/kfp_component/launcher/__main__.py", line 34, in <module>
main()
File "/ml/kfp_component/launcher/__main__.py", line 31, in main
launch(args.file_or_module, args.args)
File "kfp_component/launcher/launcher.py", line 45, in launch
return fire.Fire(module, command=args, name=module.__name__)
File "/usr/local/lib/python2.7/site-packages/fire/core.py", line 127, in Fire
component_trace = _Fire(component, args, context, name)
File "/usr/local/lib/python2.7/site-packages/fire/core.py", line 366, in _Fire
component, remaining_args)
File "/usr/local/lib/python2.7/site-packages/fire/core.py", line 542, in _CallCallable
result = fn(*varargs, **kwargs)
File "kfp_component/google/ml_engine/_deploy.py", line 68, in deploy
wait_interval)
File "kfp_component/google/ml_engine/_create_version.py", line 55, in create_version
version['deploymentUri'] = deployemnt_uri
TypeError: 'str' object does not support item assignment

# Fixed code
def create_version(
    model_name,
    deployemnt_uri=None,
    version_id=None,
    runtime_version=None,
    python_version=None,
    version=None,
    replace_existing=False,
    wait_interval=30,
    version_name_output_path="/tmp/kfp/output/ml_engine/version_name.txt",
    version_object_output_path="/tmp/kfp/output/ml_engine/version.json",
):
    """Creates a MLEngine version and wait for the operation to be done.

    Args:
        model_name (str): required, the name of the parent model.
        deployment_uri (str): optional, the Google Cloud Storage location of
            the trained model used to create the version.
        version_id (str): optional, the user provided short name of
            the version. If it is not provided, the operation uses a random name.
        runtime_version (str): optinal, the Cloud ML Engine runtime version
            to use for this deployment. If not set, Cloud ML Engine uses
            the default stable version, 1.0.
        python_version (str): optinal, the version of Python used in prediction.
            If not set, the default version is '2.7'. Python '3.5' is available
            when runtimeVersion is set to '1.4' and above. Python '2.7' works
            with all supported runtime versions.
        version (dict): optional, the payload of the new version.
        replace_existing (boolean): boolean flag indicates whether to replace
            existing version in case of conflict.
        wait_interval (int): the interval to wait for a long running operation.
    """
    if not version:
        version = {}
    if deployemnt_uri:
        version["deploymentUri"] = deployemnt_uri
    if version_id:
        version["name"] = version_id
    if runtime_version:
        version["runtimeVersion"] = runtime_version
    if python_version:
        version["pythonVersion"] = python_version

    return CreateVersionOp(
        model_name,
        version,
        replace_existing,
        wait_interval,
        version_name_output_path=version_name_output_path,
        version_object_output_path=version_object_output_path,
    ).execute_and_wait()