How to automatically trigger the materialization o...
# ask-ai
m
How to automatically trigger the materialization of an asset when its upstream dependency has been materialized
s
To automatically trigger the materialization of an asset when its upstream dependency has been materialized, you can use an
AutoMaterializePolicy
. This policy consists of a set of
AutoMaterializeRules
, each representing individual reasons that an asset should be materialized or not at a given point in time. Here's how you can set it up: 1. Enable Auto-Materialization: First, ensure that auto-materialization is enabled in your Dagster deployment. In the Dagster UI, you can find a toggle under "Deployment" > "Daemons" for open source deployments, or under "Deployment" > "Agents" > "Cloud service statuses" for Dagster Cloud. 2. Define the Policy: Assign an
AutoMaterializePolicy
to your asset. You can start with the built-in
AutoMaterializePolicy.eager
and customize it if necessary. This policy includes all supported rules except
materialize_on_cron
and
skip_on_not_all_parents_updated
. 3. Apply the Policy: Apply the
AutoMaterializePolicy
to your asset definition. If there's at least one rule determining that the asset should be materialized, and no rules determining that it should be skipped, a run will be launched to materialize that asset. Here's an example of how you might define an asset with an auto-materialization policy:
Copy code
python from dagster import asset, AutoMaterializePolicy  @asset(auto_materialize_policy=AutoMaterializePolicy.eager()) def my_asset(upstream_asset):     # Your asset computation logic here     pass
In this example,
my_asset
will be automatically materialized when its upstream dependency
upstream_asset
has been materialized, as per the eager policy. Remember that the
AutoMaterializePolicy
can be customized with different rules to fit your specific use case. For more detailed information and examples, you should refer to the [Auto-Materializing Assets documentation](https://docs.dagster.io/concepts/assets/asset-auto-execution).