Repository: kedro-org/kedro

Issue:
`kedro pipeline create` does not work when changing `base_env` name
## Description
`kedro pipeline create` does not work if the project has updated `base_env`.  

## Context
I was trying to create a new pipeline in my project using `kedro pipeline create data_processing`, I got an error saying kedro was unable to locate environment `base`. I have no `base` env because I changed my `base_env` in config loader to `prd`, below is my code:
```
CONFIG_LOADER_CLASS = OmegaConfigLoader
# Keyword arguments to pass to the `CONFIG_LOADER_CLASS` constructor.
CONFIG_LOADER_ARGS = {
    "base_env": "prd",
    "default_run_env": "local",
    "config_patterns": {
        "catalog": ["catalog*", "catalog*/**", "**/catalog*"],
        "credentials": ["credentials*", "credentials*/**", "**/credentials*"],
        "logging": ["logging*", "logging*/**", "**/logging*"],
        "parameters": ["parameters*", "parameters*/**", "**/parameters*"],
        "spark": ["spark*", "spark*/**"],
    }
}
```
To confirm the issue, I changed the `conf/prd` folder to `conf/base` and reran `kedro pipeline create`, it ran successfully and created a pipeline.

## Steps to Reproduce
1. Modify the `base_env` name in the config loader.
2. Run `kedro pipeline create`

## Expected Result
Should setup a new pipeline in `src/.../pipelines`

## Actual Result
Got an error:
```
Traceback (most recent call last):
  File "~/python3.10/site-packages/click/core.py", line 1078, in main
    rv = self.invoke(ctx)
  File "~/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/python3.10/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "~/python3.10/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "~/python3.10/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "~/python3.10/site-packages/click/decorators.py", line 45, in new_func
    return f(get_current_context().obj, *args, **kwargs)
  File "~/python3.10/site-packages/kedro/framework/cli/pipeline.py", line 116, in create_pipeline
    raise KedroCliError(
kedro.framework.cli.utils.KedroCliError: Unable to locate environment 'base'. Make sure it exists in the project configuration.
```


## Your Environment

* Kedro version used (`pip show kedro` or `kedro -V`): kedro, version 0.19.3
* Python version used (`python -V`): Python 3.10.13
* Operating system and version: Mac Sonoma 14.3



Discussion:
Thanks @markdruffel-8451 for reporting this, I've been able to reproduce it.
You could try using `kedro pipeline create <pipeline_name> --env=prod` to get around this.


Resolving patch:
diff --git a/kedro/framework/cli/pipeline.py b/kedro/framework/cli/pipeline.py
--- a/kedro/framework/cli/pipeline.py
+++ b/kedro/framework/cli/pipeline.py
@@ -110,8 +110,8 @@ def create_pipeline(
     package_dir = metadata.source_dir / metadata.package_name
     conf_source = settings.CONF_SOURCE
     project_conf_path = metadata.project_path / conf_source
-
-    env = env or "base"
+    base_env = settings.CONFIG_LOADER_ARGS.get("base_env", "base")
+    env = env or base_env
     if not skip_config and not (project_conf_path / env).exists():
         raise KedroCliError(
             f"Unable to locate environment '{env}'. "
@@ -152,8 +152,8 @@ def delete_pipeline(
     package_dir = metadata.source_dir / metadata.package_name
     conf_source = settings.CONF_SOURCE
     project_conf_path = metadata.project_path / conf_source
-
-    env = env or "base"
+    base_env = settings.CONFIG_LOADER_ARGS.get("base_env", "base")
+    env = env or base_env
     if not (project_conf_path / env).exists():
         raise KedroCliError(
             f"Unable to locate environment '{env}'. "


Test patch: