# Buggy code
def _fetch_project(uri, subdirectory, version, dst_dir, git_username, git_password):
    """
    Fetches the project from the uri. Makes sure the uri contains a valid MLproject file.
    Returns the working directory for running the project.
    """
    # Download a project to the target `dst_dir` from a Git URI or local path.
    if _GIT_URI_REGEX.match(uri):
        # Use Git to clone the project
        _fetch_git_repo(uri, version, dst_dir, git_username, git_password)
    else:
        if version is not None:
            raise ExecutionException(
                "Setting a version is only supported for Git project URIs"
            )
        # TODO: don't copy mlruns directory here
        # Note: uri might be equal to dst_dir, e.g. if we're not using a temporary work dir
        if uri != dst_dir:
            dir_util.copy_tree(src=uri, dst=dst_dir)

    # Make sure they don't have an outputs or mlruns directory (will need to change if we change
    # how we log results locally)
    shutil.rmtree(os.path.join(dst_dir, "outputs"), ignore_errors=True)
    shutil.rmtree(os.path.join(dst_dir, "mlruns"), ignore_errors=True)

    # Make sure there is a MLproject file in the specified working directory.
    if not os.path.isfile(os.path.join(dst_dir, subdirectory, "MLproject")):
        if subdirectory == "":
            raise ExecutionException("No MLproject file found in %s" % uri)
        else:
            raise ExecutionException(
                "No MLproject file found in subdirectory %s of %s" % (subdirectory, uri)
            )

    return os.path.join(dst_dir, subdirectory)


# Traceback (Exception)
(rr-sample-reg) ip-10-10-180-57:rr-sample-regression arinto$ mlflow run /Users/arinto/repository/github/rr-sample-regression -e main -P lr_feature="Employment rate as pct"
=== Fetching project from /Users/arinto/repository/github/rr-sample-regression ===
=== Work directory for this run: /Users/arinto/repository/github/rr-sample-regression ===
=== Created directory /var/folders/fd/h7tg23rd2p3cx7mnp7j47_gw0000gn/T/tmpyzpx3_w9 for downloading remote URIs passed to arguments of type 'path' ===
Traceback (most recent call last):
File "/Users/arinto/anaconda3/envs/rr-sample-reg/bin/mlflow", line 11, in <module>
sys.exit(cli())
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/click/core.py", line 722, in __call__
return self.main(*args, **kwargs)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/click/core.py", line 697, in main
rv = self.invoke(ctx)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/click/core.py", line 1066, in invoke
return _process_result(sub_ctx.command.invoke(sub_ctx))
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/click/core.py", line 895, in invoke
return ctx.invoke(self.callback, **ctx.params)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/click/core.py", line 535, in invoke
return callback(*args, **kwargs)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/cli.py", line 108, in run
storage_dir=storage_dir)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/projects.py", line 285, in run
storage_dir=storage_dir, git_username=git_username, git_password=git_password)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/projects.py", line 248, in _run_local
_run_project(project, entry_point, work_dir, parameters, use_conda, storage_dir, experiment_id)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/projects.py", line 415, in _run_project
source_type=SourceType.PROJECT)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/tracking/__init__.py", line 257, in start_run
entry_point_name, source_type)
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/tracking/__init__.py", line 222, in _do_start_run
source_version=(source_version or _get_source_version()), tags=[])
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/store/file_store.py", line 150, in create_run
if self.get_experiment(experiment_id) is None:
File "/Users/arinto/anaconda3/envs/rr-sample-reg/lib/python3.6/site-packages/mlflow/store/file_store.py", line 116, in get_experiment
raise Exception("Could not find experiment with ID %s" % experiment_id)
Exception: Could not find experiment with ID 1

# Fixed code
def _fetch_project(uri, subdirectory, version, dst_dir, git_username, git_password):
    """
    Fetches the project from the uri. Makes sure the uri contains a valid MLproject file.
    Returns the working directory for running the project.
    """
    # Download a project to the target `dst_dir` from a Git URI or local path.
    if _GIT_URI_REGEX.match(uri):
        # Use Git to clone the project
        _fetch_git_repo(uri, version, dst_dir, git_username, git_password)
    else:
        if version is not None:
            raise ExecutionException(
                "Setting a version is only supported for Git project URIs"
            )
        # TODO: don't copy mlruns directory here
        # Note: uri might be equal to dst_dir, e.g. if we're not using a temporary work dir
        if uri != dst_dir:
            dir_util.copy_tree(src=uri, dst=dst_dir)

    # Make sure there is a MLproject file in the specified working directory.
    if not os.path.isfile(os.path.join(dst_dir, subdirectory, "MLproject")):
        if subdirectory == "":
            raise ExecutionException("No MLproject file found in %s" % uri)
        else:
            raise ExecutionException(
                "No MLproject file found in subdirectory %s of %s" % (subdirectory, uri)
            )

    return os.path.join(dst_dir, subdirectory)