https://dagster.io/ logo
#ask-ai
Title
# ask-ai
a

Andy Smith

03/05/2024, 4:19 PM
For a given run of a dbt asset, how can I supply config so that dbt performs a full refresh
s

Scout

03/05/2024, 4:19 PM
To perform a full refresh of a dbt asset during a run, you can supply custom configuration to the underlying op that backs your software-defined assets. This configuration can be passed through Dagster's run configuration system. Here's an example from the documentation that demonstrates how to use the
--full-refresh
flag with
@dbt_assets
by adding a custom configuration class:
Copy code
python from pathlib import Path from dagster import AssetExecutionContext, Config from dagster_dbt import dbt_assets, DbtCliResource  class MyDbtConfig(Config):     full_refresh: bool  @dbt_assets(manifest=Path("target", "manifest.json")) def my_dbt_assets(context: AssetExecutionContext, dbt: DbtCliResource, config: MyDbtConfig):     dbt_build_args = ["build"]     if config.full_refresh:         dbt_build_args += ["--full-refresh"]      yield from dbt.cli(dbt_build_args, context=context).stream()
When you define a job that includes these dbt assets, you can specify the
full_refresh
configuration to be
True
in the
RunConfig
. This will ensure that the dbt models are fully refreshed during the run:
Copy code
python from dagster import define_asset_job, AssetSelection, RunConfig  dbt_incremental_full_refresh_job = define_asset_job(     "dbt_incremental_full_refresh_job",     selection=AssetSelection(my_dbt_assets),     config=RunConfig({"my_dbt_assets": MyDbtConfig(full_refresh=True)}), )
When you execute this job, Dagster will pass the
--full-refresh
flag to the dbt CLI command, triggering a full refresh of the dbt models.