Skip to content

Commit

Permalink
[dagster-dbt] Remove --use-dbt-project flag from docs (#23263)
Browse files Browse the repository at this point in the history
This PR updates to remove the `--use-dbt-project` flag in the docs.

Also mark the `DbtCliResource` strategy for generating the manifest as
legacy in the reference.

make apidoc-build
BK

(cherry picked from commit 6b23e32)
  • Loading branch information
maximearmstrong authored and jmsanders committed Aug 7, 2024
1 parent 5611882 commit c2afce3
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 158 deletions.
Binary file modified docs/content/api/modules.json.gz
Binary file not shown.
Binary file modified docs/content/api/searchindex.json.gz
Binary file not shown.
Binary file modified docs/content/api/sections.json.gz
Binary file not shown.
2 changes: 1 addition & 1 deletion docs/content/integrations/dbt/quickstart.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ This approach uses the `dagster-dbt` CLI to create a new Dagster project and wra
In our example, our command would look like this:

```shell
dagster-dbt project scaffold --project-name my_dagster_project --dbt-project-dir ./my_dbt_project --use-dbt-project
dagster-dbt project scaffold --project-name my_dagster_project --dbt-project-dir ./my_dbt_project
```

This command will create a new directory called `my_dagster_project/` inside the current directory. The new `my_dagster_project/` directory will contain a set of files that define a Dagster project to load the dbt project provided in `./my_dbt_project`.
Expand Down
116 changes: 10 additions & 106 deletions docs/content/integrations/dbt/reference.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ For a step-by-step implementation walkthrough, refer to the [Using dbt with Dags
You can create a Dagster project that wraps your dbt project by using the [`dagster-dbt project scaffold`](/\_apidocs/libraries/dagster-dbt#dagster-dbt-project-scaffold) command line interface.

```shell
dagster-dbt project scaffold --use-dbt-project --project-name project_dagster --dbt-project-dir path/to/dbt/project
dagster-dbt project scaffold --project-name project_dagster --dbt-project-dir path/to/dbt/project
```

This creates a directory called `project_dagster/` inside the current directory. The `project_dagster/` directory contains a set of files that define a Dagster project that loads the dbt project at the path defined by `--dbt-project-dir`. The path to the dbt project must contain a `dbt_project.yml`.
Expand All @@ -81,25 +81,11 @@ The manifest can be created in two ways:

When deploying your Dagster project to production, **we recommend generating the manifest at build time** to avoid the overhead of recompiling your dbt project every time your Dagster code is executed. A `manifest.json` should be precompiled and included in the Python package for your Dagster code.

<TabGroup>
<TabItem name="Select an option">

Select one of the following to handle the creation of your manifest:

- [**Option 1:**](#option-1-using-dbtproject) Using `DbtProject`
- [**Option 2:**](#option-2-using-dbtcliresource) Using `DbtCliResource`

</TabItem>
<TabItem name="Option 1 (recommended): Using DbtProject">

### Option 1: Using DbtProject

The easiest way to handle the creation of your manifest file is to use <PyObject object="DbtProject" module="dagster_dbt" />.

In the Dagster project created by the [`dagster-dbt project scaffold`](/\_apidocs/libraries/dagster-dbt#dagster-dbt-project-scaffold) command, the creation of your manifest is handled during development:
In the Dagster project created by the [`dagster-dbt project scaffold`](/\_apidocs/libraries/dagster-dbt#dagster-dbt-project-scaffold) command, the creation of your manifest is handled at run time during development:

```python startafter=start_compile_dbt_manifest_with_dbt_project endbefore=end_compile_dbt_manifest_with_dbt_project file=/integrations/dbt/dbt.py dedent=4
"""✅ This is recommended!"""
from pathlib import Path

from dagster_dbt import DbtProject
Expand All @@ -123,80 +109,6 @@ dagster dev

In production, a precompiled manifest should be used. Using <PyObject object="DbtProject" module="dagster_dbt" />, the manifest can be created at build time by running the [`dagster-dbt project prepare-and-package`](/\_apidocs/libraries/dagster-dbt#dagster-dbt-project-prepare-and-package) command in your CI/CD workflow. For more information, see the [Deploying a Dagster project with a dbt project](#deploying-a-dagster-project-with-a-dbt-project) section.

</TabItem>
<TabItem name="Option 2: Using DbtCliResource">

### Option 2: Using DbtCliResource

Creating the manifest can be done by running `dbt parse` using the CLI with <PyObject object="DbtCliResource" module="dagster_dbt" />.

Creating the manifest at runtime in production is known to cause issues and is not recommended. This is often caused by the following code and should be avoided.

```python startafter=start_troubleshooting_dbt_manifest endbefore=end_troubleshooting_dbt_manifest file=/integrations/dbt/dbt.py dedent=4
"""❌ This is not recommended."""
from pathlib import Path

from dagster_dbt import DbtCliResource

dbt_project_dir = Path(__file__).joinpath("..", "..", "..").resolve()
dbt = DbtCliResource(project_dir=dbt_project_dir)

# A manifest will always be created at runtime.
dbt_manifest_path = (
dbt.cli(
["--quiet", "parse"],
target_path=Path("target"),
)
.wait()
.target_path.joinpath("manifest.json")
)
```

To avoid any issues, we recommend that the manifest is created at run time only during local development. In production, the manifest should be created at build time.

In the Dagster project created by the [`dagster-dbt project scaffold`](/\_apidocs/libraries/dagster-dbt#dagster-dbt-project-scaffold) command line interface, we offer you both ways to load your dbt models:

```python startafter=start_compile_dbt_manifest endbefore=end_compile_dbt_manifest file=/integrations/dbt/dbt.py dedent=4
"""✅ This is recommended!"""
import os
from pathlib import Path

from dagster_dbt import DbtCliResource

dbt_project_dir = Path(__file__).joinpath("..", "..", "..").resolve()
dbt = DbtCliResource(project_dir=dbt_project_dir)

# If DAGSTER_DBT_PARSE_PROJECT_ON_LOAD is set, a manifest will be created at runtime.
# Otherwise, we expect a manifest to be present in the project's target directory.
if os.getenv("DAGSTER_DBT_PARSE_PROJECT_ON_LOAD"):
dbt_manifest_path = (
dbt.cli(
["--quiet", "parse"],
target_path=Path("target"),
)
.wait()
.target_path.joinpath("manifest.json")
)
else:
dbt_manifest_path = dbt_project_dir.joinpath("target", "manifest.json")
```

As the comment explains, the code gives you a choice about how to create this dbt manifest. Based on the `DAGSTER_DBT_PARSE_PROJECT_ON_LOAD` environment variable, either:

1. **At run time**: This code generates the `manifest.json` for you. This is the easiest option during development because you never need to worry about the file being out-of-date with your dbt project, or
2. **At build time**: This code leaves it up to you to generate the `manifest.json` file on your own, and this code just reads it.

When developing locally, you can run the following command to generate the manifest at run time for your dbt and Dagster project:

```shell
DAGSTER_DBT_PARSE_PROJECT_ON_LOAD=1 dagster dev
```

In production, `DAGSTER_DBT_PARSE_PROJECT_ON_LOAD` should be unset so that your project uses the precompiled manifest.

</TabItem>
</TabGroup>

---

## Deploying a Dagster project with a dbt project
Expand All @@ -220,14 +132,10 @@ In your CI/CD workflows for your Dagster project:

1. Include any secrets that are required by your dbt project in your CI/CD environment.
2. Clone the dbt project repository as a subdirectory of your Dagster project.
3. Depending on whether <PyObject object="DbtCliProject" module="dagster_dbt" /> is used, this step will vary:
- **For projects using `DbtProject`**, run `dagster-dbt project prepare-and-package --file path/to/project.py` to
- Build your dbt project's dependencies,
- Create a dbt manifest for your Dagster project, and
- Package your dbt project
- **For projects using `DbtCliResource`**:
- Run `dbt deps` to build your dbt project's dependencies
- Run `dbt parse` to create a dbt manifest for your Dagster project
3. Run `dagster-dbt project prepare-and-package --file path/to/project.py` to
- Build your dbt project's dependencies,
- Create a dbt manifest for your Dagster project, and
- Package your dbt project

In the CI/CD workflows for your dbt project, set up a dispatch action to trigger a deployment of your Dagster project when your dbt project changes.

Expand All @@ -244,14 +152,10 @@ If you are managing your Dagster project in the same git repository as your dbt
In your CI/CD workflows for your Dagster and dbt project:

1. Include any secrets that are required by your dbt project in your CI/CD environment.
2. Depending on whether <PyObject object="DbtCliProject" module="dagster_dbt" /> is used, this step will vary:
- **For projects using `DbtProject`**, run `dagster-dbt project prepare-and-package --file path/to/project.py` to
- Build your dbt project's dependencies,
- Create a dbt manifest for your Dagster project, and
- Package your dbt project
- **For projects using `DbtCliResource`**:
- Run `dbt deps` to build your dbt project's dependencies
- Run `dbt parse` to create a dbt manifest for your Dagster project
2. Run `dagster-dbt project prepare-and-package --file path/to/project.py` to
- Build your dbt project's dependencies,
- Create a dbt manifest for your Dagster project, and
- Package your dbt project

---

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ In this section, you'll finally begin integrating dbt with Dagster! To do this,
You can create a Dagster project that wraps your dbt project by using the `dagster-dbt` command line interface. Make sure you're in the directory where your `dbt_project.yml` is. If you're continuing from the previous section, then you'll already be in this directory. Then, run:

```shell
dagster-dbt project scaffold --use-dbt-project --project-name jaffle_dagster
dagster-dbt project scaffold --project-name jaffle_dagster
```

This creates a directory called `jaffle_dagster/` inside the current directory. The `jaffle_dagster/` directory contains a set of files that define a Dagster project.
Expand Down
50 changes: 0 additions & 50 deletions examples/docs_snippets/docs_snippets/integrations/dbt/dbt.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,58 +3,8 @@
MANIFEST_PATH = ""


def scope_compile_dbt_manifest(manifest):
# start_compile_dbt_manifest
"""✅ This is recommended!"""
import os
from pathlib import Path

from dagster_dbt import DbtCliResource

dbt_project_dir = Path(__file__).joinpath("..", "..", "..").resolve()
dbt = DbtCliResource(project_dir=dbt_project_dir)

# If DAGSTER_DBT_PARSE_PROJECT_ON_LOAD is set, a manifest will be created at runtime.
# Otherwise, we expect a manifest to be present in the project's target directory.
if os.getenv("DAGSTER_DBT_PARSE_PROJECT_ON_LOAD"):
dbt_manifest_path = (
dbt.cli(
["--quiet", "parse"],
target_path=Path("target"),
)
.wait()
.target_path.joinpath("manifest.json")
)
else:
dbt_manifest_path = dbt_project_dir.joinpath("target", "manifest.json")
# end_compile_dbt_manifest


def scope_troubleshooting_dbt_manifest(manifest):
# start_troubleshooting_dbt_manifest
"""❌ This is not recommended."""
from pathlib import Path

from dagster_dbt import DbtCliResource

dbt_project_dir = Path(__file__).joinpath("..", "..", "..").resolve()
dbt = DbtCliResource(project_dir=dbt_project_dir)

# A manifest will always be created at runtime.
dbt_manifest_path = (
dbt.cli(
["--quiet", "parse"],
target_path=Path("target"),
)
.wait()
.target_path.joinpath("manifest.json")
)
# end_troubleshooting_dbt_manifest


def scope_compile_dbt_manifest_with_dbt_project(manifest):
# start_compile_dbt_manifest_with_dbt_project
"""✅ This is recommended!"""
from pathlib import Path

from dagster_dbt import DbtProject
Expand Down

0 comments on commit c2afce3

Please sign in to comment.