This is an automated email from the ASF dual-hosted git repository.
pierrejeambrun 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 31f7ba74209 Fix race condition on sort param when returning dagRuns
(#68842)
31f7ba74209 is described below
commit 31f7ba742092432bd5a686ca028f62d55c257184
Author: Hasnain Raza <[email protected]>
AuthorDate: Wed Jun 24 18:17:42 2026 +0200
Fix race condition on sort param when returning dagRuns (#68842)
---
.../src/airflow/api_fastapi/common/parameters.py | 2 +-
.../unit/api_fastapi/common/test_parameters.py | 21 +++++++++++++++++++++
2 files changed, 22 insertions(+), 1 deletion(-)
diff --git a/airflow-core/src/airflow/api_fastapi/common/parameters.py
b/airflow-core/src/airflow/api_fastapi/common/parameters.py
index 17185fe20e2..935b547c1a7 100644
--- a/airflow-core/src/airflow/api_fastapi/common/parameters.py
+++ b/airflow-core/src/airflow/api_fastapi/common/parameters.py
@@ -718,7 +718,7 @@ class SortParam(BaseParam[list[str]]):
)
def inner(order_by: list[str] = _order_by_query) -> SortParam:
- return self.set_value(order_by)
+ return SortParam(self.allowed_attrs, self.model,
self.to_replace).set_value(order_by)
return inner
diff --git a/airflow-core/tests/unit/api_fastapi/common/test_parameters.py
b/airflow-core/tests/unit/api_fastapi/common/test_parameters.py
index d02496ae87d..4d2f473f4f8 100644
--- a/airflow-core/tests/unit/api_fastapi/common/test_parameters.py
+++ b/airflow-core/tests/unit/api_fastapi/common/test_parameters.py
@@ -165,6 +165,27 @@ class TestSortParam:
resolved = param.get_resolved_columns()
assert [name for name, _col, _desc in resolved] == ["import_error_id"]
+ def test_dynamic_depends_returns_independent_instances(self):
+ """Each call to the inner closure must produce a separate SortParam
instance.
+
+ Two concurrent requests with different order_by values must not share
state —
+ a mutation on one must not affect the other.
+ """
+ sort_param = SortParam(["id", "run_id", "logical_date"], DagRun,
{"dag_run_id": "run_id"})
+ inner = sort_param.dynamic_depends(default="id")
+
+ instance_a = inner(order_by=["logical_date"])
+ instance_b = inner(order_by=["run_id"])
+
+ assert instance_a is not instance_b
+ assert instance_a.value == ["logical_date"]
+ assert instance_b.value == ["run_id"]
+ # Resolving one must not affect the other.
+ cols_a = [name for name, _col, _desc in
instance_a.get_resolved_columns()]
+ cols_b = [name for name, _col, _desc in
instance_b.get_resolved_columns()]
+ assert cols_a[0] == "logical_date"
+ assert cols_b[0] == "run_id"
+
def _compile(statement):
return str(statement.compile(compile_kwargs={"literal_binds":
True})).lower()