https://dagster.io/ logo
Title
f

Fabien Gadet

02/28/2023, 10:48 PM
I'm using Dagster with DBT and i was wondering how can i run a custom command , i'm talking about this : https://docs.dagster.io/_apidocs/libraries/dagster-dbt#resources-dbt-core let's say i want to run the command
build
from dbt using the dbt cli ressource . i understood that if i want to do an
@op
i can pass a
context
parameter to use it in the function . i tried this but it doesn't work
resources = {
    "dbt": dbt_cli_resource.configured(
        {
            "project_dir": DBT_PROJECT_PATH,
            "profiles_dir": DBT_PROFILES,
        },
    )
}


@op(required_resource_keys={"dbt"})
def custom_run(context):
    context.build(models=["mymodel"])
The end goal is to do a custom
dbt build --select mymodel+
:dagster-bot-responded-by-community: 1
:dagster-bot-resolve: 1
g

Guy McCombe

03/01/2023, 2:24 PM
Hi! The op context object provides access to all of your op config and resources so you need to specify that you want to access the dbt resource. Assuming the rest of the code is correct (I don’t know enough to verify your kwargs in the build call) the correct way to call is:
@op(required_resource_keys={"dbt"})
def custom_run(context):
    context.resources.dbt.build(models=["mymodel"])
f

Fabien Gadet

03/01/2023, 2:57 PM
Indeed i was missing this resource_key . thank you very much.
g

Guy McCombe

03/01/2023, 2:57 PM
No problem! Always happy to help :daggy-love: