Fix 'Unable to find the dbt executable: dbt' error#666
Conversation
Since Cosmos 1.2.2 users who used Cosmos with ExecutionMode.LOCAL specifying:
```
execution_config = ExecutionConfig(
dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",
)
```
Started facing the issue:
```
Broken DAG: [/usr/local/airflow/dags/my_example.py] Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 178, in load
self.load_via_dbt_ls()
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 233, in load_via_dbt_ls
raise CosmosLoadDbtException(f"Unable to find the dbt executable: {self.dbt_cmd}")
cosmos.dbt.graph.CosmosLoadDbtException: Unable to find the dbt executable: dbt
```
As reported in the Airflow #airflow-astronomer Slack channel:
https://apache-airflow.slack.com/archives/C03T0AVNA6A/p1699584315506629
This PR solves the issue.
👷 Deploy Preview for amazing-pothos-a3bca0 processing.
|
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #666 +/- ##
==========================================
+ Coverage 92.72% 92.75% +0.02%
==========================================
Files 54 54
Lines 2227 2235 +8
==========================================
+ Hits 2065 2073 +8
Misses 162 162
☔ View full report in Codecov by Sentry. |
e77e940 to
590ed9a
Compare
|
@tatiana as requested, some feedback on this item and more general commentary on dbt exe path discovery. This looks like it will solve the issue of dbt command discovery at render time and make it more robust, and i had been looking to apply similar fixes in some of my previous PRs to make passing the dbt command path around more simple, but didn't due to scope. For the render time issue this looks good. I personally had an issue running on k8s at execution time (NOT Render Time) where the dbt command could not be found, and it boiled down to a documentation issue / lack of clarity for requirements on our docker image requirements for runtime. In the cosmos docs, the example we provide uses a python image as the base and we install dbt packages into that, but have no documentation on how to use the official dbt docker images. Looking at how these base python images are built (source: official library/python dockerhub images): I noticed that they have a CMD set to python, and no ENTRYPOINT defined (thus using the default of /bin/sh -c). We notice here that the ENTRYPOINT argument is set to "dbt". Since our k8s manifests we generate pass the dbt command in as "args" to the pod spec, the end result we get when using the pre-built dbt docker images is a command that looks like "dbt dbt blah" which, is not a valid command. This occurs because the entrypoint args are prefixed to whatever we pass in. For me to get the pre-baked dbt images to work, i had to add a line in my dockerfile "ENTRYPOINT []" to revert the official DBT images's commands back to the default entrypoint of ["/bin/sh", "-c"]. This, then allows the commands to run as expected at runtime. While unrelated to this render time issue, since we're updating how we deal with the dbt pathing, it is probably a worthwhile docs update to make. It would have to be something as simple as "if you want to build your own image and install dbt, make the dockerfile look like the example, else if you want to use the pre baked ones, you need to ensure the entrypoint removed (i.e []) to ensure the commands work in the current state. The other option we have is to update our k8s / docker logic to add an additional arg when we generate pod specs and override the entrypoint / command to ensure we dont use the default: https://kubernetes.io/docs/reference/generated/kubernetes-api/v1.26/ in this case - args appends to the ENTRYPOINT, command would run it without depending on the entrypoint, in theory, allowing us to consume the default dbt images without having to update the ENTRYPOINT in custom builds. |
|
Thanks, @MrBones757 , for the feedback! I've logged a task for us to improve the K8s docs: #668, to avoid other users running into the issues you faced. Thank you! |
Since Cosmos 1.2.2 users who used `ExecutionMode.DBT_LS` (directly or
via `ExecutionMode.AUTOMATIC`) and set
`ExecutionConfig.dbt_executable_path` (most, if not all, Astro CLI
users), like:
```
execution_config = ExecutionConfig(
dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",
)
```
Started facing the issue:
```
Broken DAG: [/usr/local/airflow/dags/my_example.py] Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 178, in load
self.load_via_dbt_ls()
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 233, in load_via_dbt_ls
raise CosmosLoadDbtException(f"Unable to find the dbt executable: {self.dbt_cmd}")
cosmos.dbt.graph.CosmosLoadDbtException: Unable to find the dbt executable: dbt
```
This issue was initially reported in the Airflow #airflow-astronomer
Slack channel:
https://apache-airflow.slack.com/archives/C03T0AVNA6A/p1699584315506629
The workaround to avoid this error in Cosmos 1.2.2 and 1.2.3 is to set
the `dbt_executable_path` in the `RenderConfig`:
```
render_config=RenderConfig(dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",),
```
This PR solves the bug from Cosmos 1.2.4 onwards.
(cherry picked from commit 2b61364)
Bug fixes * Store `compiled_sql` even when task fails by @agreenburg in #671 * Refactor `LoadMethod.LOCAL` to use symlinks instead of copying directory by @jbandoro in #660 * Fix 'Unable to find the dbt executable: dbt' error by @tatiana in #666 * Fix installing deps when using `profile_mapping` & `ExecutionMode.LOCAL` by @joppevos in #659 Others * Docs fix: add execution config to MWAA code example by @ugmuka in #674
Bug fixes * Store `compiled_sql` even when task fails by @agreenburg in #671 * Refactor `LoadMethod.LOCAL` to use symlinks instead of copying directory by @jbandoro in #660 * Fix 'Unable to find the dbt executable: dbt' error by @tatiana in #666 * Fix installing deps when using `profile_mapping` & `ExecutionMode.LOCAL` by @joppevos in #659 Others * Docs fix: add execution config to MWAA code example by @ugmuka in #674 (cherry picked from commit aa9b7bb)
Since Cosmos 1.2.2 users who used `ExecutionMode.DBT_LS` (directly or
via `ExecutionMode.AUTOMATIC`) and set
`ExecutionConfig.dbt_executable_path` (most, if not all, Astro CLI
users), like:
```
execution_config = ExecutionConfig(
dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",
)
```
Started facing the issue:
```
Broken DAG: [/usr/local/airflow/dags/my_example.py] Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 178, in load
self.load_via_dbt_ls()
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 233, in load_via_dbt_ls
raise CosmosLoadDbtException(f"Unable to find the dbt executable: {self.dbt_cmd}")
cosmos.dbt.graph.CosmosLoadDbtException: Unable to find the dbt executable: dbt
```
This issue was initially reported in the Airflow #airflow-astronomer
Slack channel:
https://apache-airflow.slack.com/archives/C03T0AVNA6A/p1699584315506629
The workaround to avoid this error in Cosmos 1.2.2 and 1.2.3 is to set
the `dbt_executable_path` in the `RenderConfig`:
```
render_config=RenderConfig(dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",),
```
This PR solves the bug from Cosmos 1.2.4 onwards.
(cherry picked from commit 2b61364)
Bug fixes * Store `compiled_sql` even when task fails by @agreenburg in #671 * Refactor `LoadMethod.LOCAL` to use symlinks instead of copying directory by @jbandoro in #660 * Fix 'Unable to find the dbt executable: dbt' error by @tatiana in #666 * Fix installing deps when using `profile_mapping` & `ExecutionMode.LOCAL` by @joppevos in #659 Others * Docs fix: add execution config to MWAA code example by @ugmuka in #674
**Bug fixes** * Store `compiled_sql` even when task fails by @agreenburg in #671 * Refactor `LoadMethod.LOCAL` to use symlinks instead of copying directory by @jbandoro in #660 * Fix 'Unable to find the dbt executable: dbt' error by @tatiana in #666 * Fix installing deps when using `profile_mapping` & `ExecutionMode.LOCAL` by @joppevos in #659 **Others** * Docs fix: add execution config to MWAA code example by @ugmuka in #674 (cherry picked from commit aa9b7bb)
Since Cosmos 1.2.2 users who used `ExecutionMode.DBT_LS` (directly or
via `ExecutionMode.AUTOMATIC`) and set
`ExecutionConfig.dbt_executable_path` (most, if not all, Astro CLI
users), like:
```
execution_config = ExecutionConfig(
dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",
)
```
Started facing the issue:
```
Broken DAG: [/usr/local/airflow/dags/my_example.py] Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 178, in load
self.load_via_dbt_ls()
File "/usr/local/lib/python3.11/site-packages/cosmos/dbt/graph.py", line 233, in load_via_dbt_ls
raise CosmosLoadDbtException(f"Unable to find the dbt executable: {self.dbt_cmd}")
cosmos.dbt.graph.CosmosLoadDbtException: Unable to find the dbt executable: dbt
```
This issue was initially reported in the Airflow #airflow-astronomer
Slack channel:
https://apache-airflow.slack.com/archives/C03T0AVNA6A/p1699584315506629
The workaround to avoid this error in Cosmos 1.2.2 and 1.2.3 is to set
the `dbt_executable_path` in the `RenderConfig`:
```
render_config=RenderConfig(dbt_executable_path = f"{os.environ['AIRFLOW_HOME']}/dbt_venv/bin/dbt",),
```
This PR solves the bug from Cosmos 1.2.4 onwards.
**Bug fixes** * Store `compiled_sql` even when task fails by @agreenburg in astronomer#671 * Refactor `LoadMethod.LOCAL` to use symlinks instead of copying directory by @jbandoro in astronomer#660 * Fix 'Unable to find the dbt executable: dbt' error by @tatiana in astronomer#666 * Fix installing deps when using `profile_mapping` & `ExecutionMode.LOCAL` by @joppevos in astronomer#659 **Others** * Docs fix: add execution config to MWAA code example by @ugmuka in astronomer#674 (cherry picked from commit aa9b7bb)
Since Cosmos 1.2.2 users who used
ExecutionMode.DBT_LS(directly or viaExecutionMode.AUTOMATIC) and setExecutionConfig.dbt_executable_path(most, if not all, Astro CLI users), like:Started facing the issue:
This issue was initially reported in the Airflow #airflow-astronomer Slack channel: https://apache-airflow.slack.com/archives/C03T0AVNA6A/p1699584315506629
The workaround to avoid this error in Cosmos 1.2.2 and 1.2.3 is to set the
dbt_executable_pathin theRenderConfig:This PR solves the bug from Cosmos 1.2.4 onwards.
Closes: #633