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

Greg H

03/07/2024, 4:52 PM
I have a dbt asset that depends on another asset that ingests data. How can I use auto materialisation to build the dbt asset every time the upstream assets changes?
s

Scout

03/07/2024, 4:52 PM
To achieve auto-materialization of a dbt asset when an upstream asset changes, you can use an
AutoMaterializePolicy
. According to the documentation, Dagster provides eager
AutoMaterializePolicys
which allow materializing an asset whenever its parent assets are materialized. This feature is currently marked experimental, and some of the APIs may change in the future. Here's an example of how you might define such a policy:
Copy code
python from dagster import AutoMaterializePolicy, asset  @asset def upstream_asset():     # Logic for your upstream asset that ingests data     ...  @asset(auto_materialize_policy=AutoMaterializePolicy.eager(), deps=[upstream_asset]) def dbt_asset():     # Logic for your dbt asset     ...
In this example,
dbt_asset
is set to auto-materialize eagerly whenever
upstream_asset
is materialized. This means that any time
upstream_asset
changes and is materialized,
dbt_asset
will automatically be queued for materialization as well. Remember that this feature is experimental, so you should keep an eye on the documentation for any updates or changes to the API.