This is an automated email from the ASF dual-hosted git repository.
Lee-W pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new bb5d903fa8a Rename misleading last_automated_run param to
reference_run (#68714)
bb5d903fa8a is described below
commit bb5d903fa8ae44e83b45c7c64eddfce25108aefc
Author: Wei Lee <[email protected]>
AuthorDate: Fri Jun 19 22:12:28 2026 +0800
Rename misleading last_automated_run param to reference_run (#68714)
---
airflow-core/src/airflow/dag_processing/collection.py | 4 ++--
airflow-core/src/airflow/jobs/scheduler_job_runner.py | 4 ++--
airflow-core/src/airflow/models/dag.py | 16 +++++++++-------
airflow-core/tests/unit/jobs/test_scheduler_job.py | 2 +-
airflow-core/tests/unit/models/test_dag.py | 2 +-
5 files changed, 15 insertions(+), 13 deletions(-)
diff --git a/airflow-core/src/airflow/dag_processing/collection.py
b/airflow-core/src/airflow/dag_processing/collection.py
index 16ca8a0ef24..003a4da016e 100644
--- a/airflow-core/src/airflow/dag_processing/collection.py
+++ b/airflow-core/src/airflow/dag_processing/collection.py
@@ -644,9 +644,9 @@ class DagModelOperation(NamedTuple):
dm.bundle_name = self.bundle_name
dm.bundle_version = self.bundle_version
- last_automated_run: DagRun | None = run_info.latest_run
+ reference_run: DagRun | None = run_info.latest_run
dm.exceeds_max_non_backfill = run_info.num_active_runs >=
dm.max_active_runs
- dm.calculate_dagrun_date_fields(dag,
last_automated_run=last_automated_run)
+ dm.calculate_dagrun_date_fields(dag, reference_run=reference_run)
if not dag.timetable.asset_condition:
dm.schedule_asset_references = []
dm.schedule_asset_alias_references = []
diff --git a/airflow-core/src/airflow/jobs/scheduler_job_runner.py
b/airflow-core/src/airflow/jobs/scheduler_job_runner.py
index 93b155f2257..3c5d71e9a3d 100644
--- a/airflow-core/src/airflow/jobs/scheduler_job_runner.py
+++ b/airflow-core/src/airflow/jobs/scheduler_job_runner.py
@@ -2458,7 +2458,7 @@ class SchedulerJobRunner(BaseJobRunner, LoggingMixin):
dag_id=dag_model.dag_id,
logical_date=dag_model.next_dagrun,
)
- dag_model.calculate_dagrun_date_fields(dag=serdag,
last_automated_run=dr)
+ dag_model.calculate_dagrun_date_fields(dag=serdag,
reference_run=dr)
continue
if (
@@ -2498,7 +2498,7 @@ class SchedulerJobRunner(BaseJobRunner, LoggingMixin):
partition_date=next_info.partition_date,
)
active_runs_of_dags[dag_model.dag_id] += 1
- dag_model.calculate_dagrun_date_fields(dag=serdag,
last_automated_run=created_run)
+ dag_model.calculate_dagrun_date_fields(dag=serdag,
reference_run=created_run)
self._set_exceeds_max_active_runs(
dag_model=dag_model,
session=session,
diff --git a/airflow-core/src/airflow/models/dag.py
b/airflow-core/src/airflow/models/dag.py
index adf7a5e945c..1b20a92f353 100644
--- a/airflow-core/src/airflow/models/dag.py
+++ b/airflow-core/src/airflow/models/dag.py
@@ -813,28 +813,30 @@ class DagModel(Base):
self,
dag: SerializedDAG | LazyDeserializedDAG,
*,
- last_automated_run: DagRun | None,
+ reference_run: DagRun | None,
) -> None:
"""
Calculate ``next_dagrun`` and `next_dagrun_create_after``.
:param dag: The DAG object
- :param last_automated_run: DagRun of most recent run of this dag, or
none
- if not yet scheduled.
- TODO: AIP-76 This is not always latest run! See
https://github.com/apache/airflow/issues/59618.
+ :param reference_run: The automated run used as the basis for
computing the
+ next run, or None if not yet scheduled. This is the run the
scheduler is
+ currently processing, which is not necessarily the latest run of
the dag:
+ scheduler processing order and concurrent run creation in a
distributed
+ system mean a newer run may already exist.
"""
# TODO: AIP-76 perhaps we need to add validation for manual runs
ensure consistency between
# partition_key / partition_date and run_after
- if isinstance(last_automated_run, datetime):
+ if isinstance(reference_run, datetime):
raise ValueError(
"Passing a datetime to `DagModel.calculate_dagrun_date_fields`
is not supported. "
"Provide a data interval instead."
)
last_run_info = None
- if last_automated_run:
- last_run_info =
dag.timetable.run_info_from_dag_run(dag_run=last_automated_run)
+ if reference_run:
+ last_run_info =
dag.timetable.run_info_from_dag_run(dag_run=reference_run)
next_dagrun_info =
dag.next_dagrun_info(last_automated_run_info=last_run_info)
if next_dagrun_info is None:
# there is no next dag run after the last dag run; set everything
to None
diff --git a/airflow-core/tests/unit/jobs/test_scheduler_job.py
b/airflow-core/tests/unit/jobs/test_scheduler_job.py
index b312f9fd1b0..f905fccb734 100644
--- a/airflow-core/tests/unit/jobs/test_scheduler_job.py
+++ b/airflow-core/tests/unit/jobs/test_scheduler_job.py
@@ -5072,7 +5072,7 @@ class TestSchedulerJob:
bash_command="exit 1",
retries=1,
)
- dag_maker.dag_model.calculate_dagrun_date_fields(dag,
last_automated_run=None)
+ dag_maker.dag_model.calculate_dagrun_date_fields(dag,
reference_run=None)
@provide_session
def do_schedule(*, session: Session = NEW_SESSION):
diff --git a/airflow-core/tests/unit/models/test_dag.py
b/airflow-core/tests/unit/models/test_dag.py
index f09ab836b6b..da751e7dd85 100644
--- a/airflow-core/tests/unit/models/test_dag.py
+++ b/airflow-core/tests/unit/models/test_dag.py
@@ -4344,7 +4344,7 @@ def test_calculate_dagrun_date_fields(
run = dag_maker.create_dagrun()
serdag = dag_maker.serialized_dag
dag_model = dag_maker.dag_model
- dag_model.calculate_dagrun_date_fields(dag=serdag, last_automated_run=run)
+ dag_model.calculate_dagrun_date_fields(dag=serdag, reference_run=run)
assert dag_model.next_dagrun_data_interval == next_interval
assert dag_model.next_dagrun == next_run
assert dag_model.next_dagrun_create_after == next_run_after