Asset-level run configuration for direct materialization and Declarative Automation
Asset-level run configuration for direct materialization and Declarative Automation
Summary
There currently does not appear to be a way to define default run-level configuration for an individual asset that is automatically applied regardless of how that asset is materialized.
This becomes particularly problematic when using K8sRunLauncher, where an asset may require specific dagster-k8s/config run tags.
Today, the configuration has to be attached to the execution mechanism (for example, an asset job or AutomationConditionSensorDefinition) rather than being defined once alongside the asset.
Example
Suppose I have an asset that requires specific Kubernetes configuration:
@dg.asset(
automation_condition=dg.AutomationCondition.on_cron("0 * * * *"),
)
def expensive_asset():
...I would like to define its Kubernetes run configuration once, conceptually:
ASSET_RUN_TAGS = {
"dagster-k8s/config": {
"pod_spec_config": {
"node_selector": {
"workload": "expensive"
}
}
}
}and have this configuration apply whenever expensive_asset is materialized.
Current behavior
There are currently different execution paths:
Named asset job
define_asset_job(..., run_tags=...)can provide the required run tags.Declarative Automation
AutomationConditionSensorDefinition(..., run_tags=...)can provide the required run tags.Materialize now in the UI
Clicking "Materialize" on the asset uses the generic/ephemeral asset job rather than the named asset job, so the job's
run_tagsare not available.
This means I need to configure the same Kubernetes requirements in multiple places if I want both automated and manual materialization to behave consistently.
This is especially awkward because the Kubernetes configuration is really a property of how this asset needs to execute, rather than a property of which assets happen to be grouped into an asset job.
Desired behavior
I would like a supported way to specify default run tags/configuration at the asset level, for example conceptually:
@dg.asset(
run_tags={
"dagster-k8s/config": {
...
}
}
)
def expensive_asset():
...or some equivalent API.
Those defaults should then be applied when the asset is materialized through:
- "Materialize now" / direct materialization
- Declarative Automation /
AutomationCondition - an asset job, where appropriate
- other APIs that materialize the asset directly
Ideally, explicit run/job/sensor configuration could override or merge with the asset defaults.
Why asset tags are not sufficient
I understand that Dagster intentionally distinguishes asset tags from run tags, and that asset tags are metadata for organizing/filtering assets rather than configuration applied to runs.
The requirement here is specifically for default run configuration, not asset metadata.
For example, dagster-k8s/config needs to reach the run launcher so that the resulting Kubernetes Job/Pod is configured correctly.
Relationship to existing issues
This appears related to:
- #19599 — K8s config per code-location
- #26720 — Asset
op_tagsnot being propagated when materializing from the UI - #20426 — Upstream dependencies for Automaterialization, where the recommended workaround is to put
run_tagsonAutomationConditionSensorDefinition
However, those approaches still require the user to attach the configuration to different execution mechanisms.
Question
What is the recommended Dagster pattern for defining one source of truth for per-asset run configuration that must apply consistently to both:
- direct "Materialize now" executions, and
- Declarative Automation executions?
If there is intentionally no asset-level run configuration API, would Dagster consider adding one?
The goal is to avoid having to create an otherwise unnecessary define_asset_job solely to transport run configuration to Kubernetes, and then separately repeat that configuration on an AutomationConditionSensorDefinition.
Source: dagster-io/dagster