Declarative Automation includes pre-built conditions to handle common use cases, such as executing on a periodic schedule or whenever an upstream dependency updates, but you can also customize conditions.
By the end of this guide, you'll understand how AutomationConditions work and how to create your own custom conditions.
Each AutomationCondition consists of a set of operands and various operators. To create conditions that suit your specific needs, you can combine the operators and operands listed below. For example:
from dagster import AutomationCondition
in_progress_or_failed_parents = AutomationCondition.any_deps_match(
AutomationCondition.in_progress()| AutomationCondition.failed())
This condition translates to Any upstream dependencies (parents) part of an in-progress run or failed during the latest run.
The above conditions can be built into more complex expressions using the following operators:
Operator
Description
~ (tilde)
NOT; condition is not true; ex: ~A
| (pipe)
OR; either condition must be true; ex: A | B
& (ampersand)
AND; both conditions must be true; ex: A & B
A.newly_true()
Condition A was false on the previous evaluation and is now true.
A.since(B)
Condition A became true more recently than Condition B.
AutomationCondition.any_deps_match(A)
Condition A is true for any upstream partition. Can be used with .allow() and .ignore() to target specific upstream assets. Refer to the Targeting dependencies section for an example.
AutomationCondition.all_deps_match(A)
Condition A is true for at least one partition of each upstream asset. Can be used with .allow() and .ignore() to target specific upstream assets. Refer to the Targeting dependencies section for an example.
It's common to have use cases similar to pre-built policies but with minor differences. While it is always possible to copy the base implementation and modify it as needed, it can often be simpler to use the .without() method to remove the unwanted sub-conditions or add additional conditions with the & operator.
By default, AutomationCondition.eager() will not materialize an asset partition if it has any missing dependencies. If it is expected to have missing upstream data, remove ~AutomationCondition.any_deps_missing() from the eager policy to allow execution:
from dagster import AutomationCondition
condition = AutomationCondition.eager().without(~AutomationCondition.any_deps_missing(),)
AutomationCondition.eager(): Update older time partitions#
By default, AutomationCondition.eager() will only update the latest time partition of an asset. If updates to historical partitions should result in downstream updates, then this sub-condition can be removed:
from dagster import AutomationCondition
condition = AutomationCondition.eager().without(
AutomationCondition.in_latest_time_window(),)
Upstream assets commonly influence downstream materialization decisions. To create automation conditions that target dependencies, use the AutomationCondition.any_deps_match() operator. This operator takes an arbitrary AutomationCondition, applies it to each upstream asset, and then maps the results to the corresponding downstream partitions.
This operator and AutomationCondition.all_deps_match() can be further customized to only target specific sets of upstream assets by using .allow() and .ignore().
For example, to target updates from a specific asset group, you can use any_deps_match with the newly_updated operand and tell it to target only the metrics asset group:
from dagster import AssetSelection, AutomationCondition
AutomationCondition.any_deps_match(
AutomationCondition.newly_updated()).allow(AssetSelection.groups("metrics"))
Or to ignore missing partitions from an upstream asset, you can use any_deps_match with the missing operand and tell it to ignore a specific asset:
Note that these ignore() and allow() methods also work for composite conditions such as AutomationCondition.any_deps_missing() or AutomationCondition.any_deps_updated().
When there are a large number of sub-conditions that make up an AutomationCondition, it can be difficult to understand and troubleshoot the condition. To make conditions easier to understand, you can attach labels to sub-conditions, which will then display in the Dagster UI.
Arbitrary string labels can be attached to any node in the AutomationCondition tree by using the with_label() method, allowing you to describe the purpose of a specific sub-condition. For example:
from dagster import AutomationCondition
in_progress_or_failed_parents = AutomationCondition.any_deps_match(
AutomationCondition.in_progress()| AutomationCondition.failed()).with_label("Any parents in progress or failed")
Then, when viewing evaluation results in the UI, the label will display next to the condition:
Hovering over or expanding the label will display its sub-conditions: