Add run_after support to TriggerDagRunOperator #61338
Open
+140
−18
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR adds
run_afterparameter support toTriggerDagRunOperator, enabling multiple parallel runs of the same DAG with different configurations in Airflow 3.Problem Statement
Currently,
TriggerDagRunOperatorforceslogical_dateto be set (defaulting toutcnow()if not provided), which creates a bottleneck due to the unique constraint on(dag_id, logical_date)in the database. This prevents triggering multiple parallel runs of the same DAG with differentconfvalues at runtime.In Airflow 3, the
run_afterparameter was introduced to enable this use case by allowinglogical_dateto beNone, effectively removing this limitation.Solution
Added
run_afterparameter toTriggerDagRunOperatorwith the following behavior:run_afteris provided andlogical_dateis not explicitly set,logical_dateis set toNone(dag_id, logical_date)to be satisfied by multiple runs withlogical_date=Nonerun_afterparameter supports templating for dynamic schedulingExample Usage
Before (Airflow 3 - Limited):
After (Airflow 3 - Parallel Runs Enabled):
Implementation Details
Changes Made
Added
run_afterparameter toTriggerDagRunOperator.__init__str | datetime.datetime | None | ArgNotSetNOTSET(backward compatible)Added
run_aftertotemplate_fieldsfor dynamic templating supportUpdated
execute()method logic:run_afterparameter (supports string, datetime, or None)run_afteris provided andlogical_dateisNOTSET, setlogical_date=Noneutcnow())Updated
run_idgeneration:parsed_run_afterif provided, otherwise fall back to existing logicUpdated
_trigger_dag_af_3()method:run_aftertoDagRunTriggerExceptionfor Airflow 3 compatibilityFiles Modified
providers/standard/src/airflow/providers/standard/operators/trigger_dagrun.pyBackward Compatibility
✅ Fully backward compatible
run_after=NOTSET)run_afteris explicitly providedTesting
Checklist
template_fieldsfor templating supportRelated Issue
Fixes #60443
Note: This implementation focuses on Airflow 3 compatibility. The Airflow 2 code path (
_trigger_dag_af_2) remains unchanged as it may not supportrun_afterin thetrigger_dag()API.