This is an automated email from the ASF dual-hosted git repository.
potiuk 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 484bf409d51 Fix flaky test_get_last_ti_with_multiple_tis by ensuring
natural task_id sorting using natsort (#53782)
484bf409d51 is described below
commit 484bf409d510ef31a9323fb29dbbacdb018d3229
Author: Kyungjun Lee <[email protected]>
AuthorDate: Sat Jul 26 21:47:51 2025 +0900
Fix flaky test_get_last_ti_with_multiple_tis by ensuring natural task_id
sorting using natsort (#53782)
* CHG: Ensure deterministic task ordering using natsort
* ADD: natsorted pkg
---
airflow-core/src/airflow/models/dagrun.py | 6 +++++-
pyproject.toml | 1 +
2 files changed, 6 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/models/dagrun.py
b/airflow-core/src/airflow/models/dagrun.py
index d546160ad28..abab6658d33 100644
--- a/airflow-core/src/airflow/models/dagrun.py
+++ b/airflow-core/src/airflow/models/dagrun.py
@@ -30,6 +30,7 @@ from typing import (
overload,
)
+from natsort import natsorted
from sqlalchemy import (
JSON,
Column,
@@ -1373,7 +1374,10 @@ class DagRun(Base, LoggingMixin):
if dag.partial:
tis = [ti for ti in tis if not ti.state == State.NONE]
# filter out removed tasks
- tis = [ti for ti in tis if ti.state != TaskInstanceState.REMOVED]
+ tis = natsorted(
+ (ti for ti in tis if ti.state != TaskInstanceState.REMOVED),
+ key=lambda ti: ti.task_id,
+ )
if not tis:
return None
ti = tis[-1] # get last TaskInstance of DagRun
diff --git a/pyproject.toml b/pyproject.toml
index eadbc33185f..db28b15a90b 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -69,6 +69,7 @@ version = "3.1.0"
dependencies = [
"apache-airflow-task-sdk<1.2.0,>=1.0.0",
"apache-airflow-core==3.1.0",
+ "natsort>=8.4.0",
]
packages = []