astronomer-cosmos
astronomer-cosmos copied to clipboard
Is it possible to run a single dbt model as a task?
I am opening this issue because I couldn't run a single dbt model as task in Airflow with Cosmos with one profile config. I wouldn't like to run a DbtDag or a DbtTaskGroup with all my models in my dbt folder. I would like to run just one model, specifying its path, using only on profile.yml. Is that possible?
I ran:
dbt_task= DbtTaskGroup(
group_id="dbt_task",
project_config=ProjectConfig(
(dbt_root_path / "my_project/models/some_model/").as_posix(),
),
operator_args={"install_deps": True},
profile_config=profile_config,
default_args={"retries": 2},
)
But I get a cosmos.exceptions.CosmosValueError: Could not find dbt_project.yml at {path}
. I should either copy the dbt_project.yml
from root or set the project_config
as dbt_root_path / "my_project/
path, but it finds all models.
Is there a way to run a single model as a task or I have to run all models in the project invariably?
Hi @luis-fnogueira , could you confirm which version of Cosmos you are using?
It seems there are two issues you're describing, that are unrelated:
1. Profile yml path
The error you described, cosmos.exceptions.CosmosValueError: Could not find dbt_project.yml at {path}
, is related to not finding dbt_project.yml
:
https://github.com/astronomer/astronomer-cosmos/blob/73a9ba2b0497e9043e6bcaadf77b24f050424333/cosmos/config.py#L205
Cosmos can reference this file in any directory as long as the process running Airflow has permission to access it.
- Running a single model
There are a few options. Similar to the dbt
command, Cosmos exposes select
and exclude
. You could write a selector to pick the only model you're interested in running:
https://astronomer.github.io/astronomer-cosmos/configuration/selecting-excluding.html
Since you only want to run a model, another option would be to use a Cosmos operator directly, without the need of using DbtDag
or DbtTaskGroup
:
https://github.com/astronomer/astronomer-cosmos/blob/73a9ba2b0497e9043e6bcaadf77b24f050424333/tests/operators/test_local.py#L398-L405
Since we don't have further details, we're closing this issue. Please, @luis-fnogueira reopen it with more information if you're still facing problems.