Repository: dbt-labs/dbt-core

Issue:
[CT-2743] [Bug] `dbt docs serve` does not respect new input method for `target-path`
### Is this a new bug in dbt-core?

- [X] I believe this is a new bug in dbt-core
- [X] I have searched the existing issues, and I could not find an existing issue for this bug

### Current Behavior

DBT 1.5 warns that `target-path` in `dbt_project.yml` is deprecated and should be replaced with `--target-path` or `$DBT_TARGET_PATH`.

We removed `target-path` from our `dbt_project.yml` and `dbt debug` reports all green:

```
18:03:06  Running with dbt=1.5.1
18:03:06  dbt version: 1.5.1
18:03:06  python version: 3.9.17
18:03:06  python path: /project/.meltano/transformers/dbt-postgres/venv/bin/python
18:03:06  os info: Linux-4.14.311-233.529.amzn2.x86_64-x86_64-with-glibc2.36
18:03:06  Using profiles.yml file at /project/transform/profiles/postgres/profiles.yml
18:03:06  Using dbt_project.yml file at /project/transform/dbt_project.yml
18:03:06  Configuration:
18:03:06    profiles.yml file [OK found and valid]
18:03:06    dbt_project.yml file [OK found and valid]
18:03:06  Required dependencies:
18:03:06   - git [OK found]
```

However, when we start the docs server it errors trying to read the target:

```
18:02:38  Running with dbt=1.5.1
18:02:38  Encountered an error:
[Errno 2] No such file or directory: 'target'
18:02:38  Traceback (most recent call last):
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/cli/requires.py", line 86, in wrapper
    result, success = func(*args, **kwargs)
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/cli/requires.py", line 71, in wrapper
    return func(*args, **kwargs)
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/cli/requires.py", line 142, in wrapper
    return func(*args, **kwargs)
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/cli/requires.py", line 168, in wrapper
    return func(*args, **kwargs)
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/cli/requires.py", line 215, in wrapper
    return func(*args, **kwargs)
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/cli/main.py", line 299, in docs_serve
    results = task.run()
  File "/project/.meltano/transformers/dbt-postgres/venv/lib/python3.9/site-packages/dbt/task/serve.py", line 15, in run
    os.chdir(self.config.target_path)
FileNotFoundError: [Errno 2] No such file or directory: 'target'
```

Putting `target-path` back resolves the issue, while returning the warning about deprecation:

```
18:08:58  Running with dbt=1.5.1
18:08:58  [WARNING]: Deprecated functionality
The `target-path` config in `dbt_project.yml` has been deprecated, and will no
longer be supported in a future version of dbt-core. If you wish to write dbt
artifacts to a custom directory, please use the --target-path CLI flag or
DBT_TARGET_PATH env var instead.
Serving docs at 6450
To access from your browser, navigate to: http://localhost:6450



Press Ctrl+C to exit.
```

Interestingly, `dbt docs generate` does respect the new target path config, it's only when then serving said config that it breaks.

### Expected Behavior

The `dbt docs serve` command should respond to `--target-path` and respect `$DBT_TARGET_PATH`, starting without error if an alternate target path was used to generate.

### Steps To Reproduce

1. Remove `target-path: my_target_dir` from `dbt_project.yml`
2. `export DBT_TARGET_PATH=my_target_dir`
3. `dbt docs generate` (`Catalog written to my_target_dir/catalog.json`)
4. `dbt docs serve`

### Relevant log output

_No response_

### Environment

```markdown
- OS: `python:3.9` Docker Image (Debian 12)
- Python: 3.9
- dbt: 1.5.1
```


### Which database adapter are you using with dbt?

postgres

### Additional Context

Possibly related to https://github.com/dbt-labs/dbt-core/issues/7418


Discussion:

Resolving patch:
diff --git a/core/dbt/cli/main.py b/core/dbt/cli/main.py
--- a/core/dbt/cli/main.py
+++ b/core/dbt/cli/main.py
@@ -213,6 +213,7 @@ def build(ctx, **kwargs):
 @p.profiles_dir
 @p.project_dir
 @p.target
+@p.target_path
 @p.vars
 @requires.postflight
 @requires.preflight
@@ -283,6 +284,7 @@ def docs_generate(ctx, **kwargs):
 @p.profiles_dir
 @p.project_dir
 @p.target
+@p.target_path
 @p.vars
 @requires.postflight
 @requires.preflight
@@ -476,6 +478,7 @@ def init(ctx, **kwargs):
 @p.state
 @p.deprecated_state
 @p.target
+@p.target_path
 @p.vars
 @requires.postflight
 @requires.preflight
@@ -576,6 +579,7 @@ def run(ctx, **kwargs):
 @p.profiles_dir
 @p.project_dir
 @p.target
+@p.target_path
 @p.vars
 @requires.postflight
 @requires.preflight
@@ -690,6 +694,7 @@ def source(ctx, **kwargs):
 @p.state
 @p.deprecated_state
 @p.target
+@p.target_path
 @p.threads
 @p.vars
 @requires.postflight


Test patch: