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 6e97d872d72 Filter stale Dag tags from public API (#66827) (#69156)
6e97d872d72 is described below

commit 6e97d872d72657cdf29e9760af175e5dd0fbbcfc
Author: Deepak Jain <[email protected]>
AuthorDate: Mon Jul 6 15:36:51 2026 +0530

    Filter stale Dag tags from public API (#66827) (#69156)
    
    * Filter stale Dag tags from public API (#66827)
    
    * Add newsfragment for stale Dag tags (#66827)
    
    * Remove stale Dag tags newsfragment (#66827)
---
 .../airflow/api_fastapi/core_api/routes/public/dag_tags.py    | 11 ++++++++---
 .../unit/api_fastapi/core_api/routes/public/test_dag_tags.py  |  9 ++++++++-
 2 files changed, 16 insertions(+), 4 deletions(-)

diff --git 
a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_tags.py 
b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_tags.py
index b09f524c1ac..d31c71c89c8 100644
--- a/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_tags.py
+++ b/airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_tags.py
@@ -21,7 +21,7 @@ from collections.abc import Sequence
 from typing import Annotated
 
 from fastapi import Depends
-from sqlalchemy import select
+from sqlalchemy import false, select
 
 from airflow.api_fastapi.common.db.common import (
     SessionDep,
@@ -37,7 +37,7 @@ from airflow.api_fastapi.common.parameters import (
 from airflow.api_fastapi.common.router import AirflowRouter
 from airflow.api_fastapi.core_api.datamodels.dag_tags import 
DAGTagCollectionResponse
 from airflow.api_fastapi.core_api.security import ReadableTagsFilterDep, 
requires_access_dag
-from airflow.models.dag import DagTag
+from airflow.models.dag import DagModel, DagTag
 
 dag_tags_router = AirflowRouter(tags=["DAG"], prefix="/dagTags")
 
@@ -61,7 +61,12 @@ def get_dag_tags(
     session: SessionDep,
 ) -> DAGTagCollectionResponse:
     """Get all Dag tags."""
-    query = select(DagTag.name).group_by(DagTag.name)
+    query = (
+        select(DagTag.name)
+        .join(DagModel, DagModel.dag_id == DagTag.dag_id)
+        .where(DagModel.is_stale == false())
+        .group_by(DagTag.name)
+    )
     dag_tags_select, total_entries = paginated_select(
         statement=query,
         filters=[tag_name_pattern, tag_name_prefix_pattern, 
readable_tags_filter],
diff --git 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_tags.py 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_tags.py
index 2692ea07ff1..62ba3ae257d 100644
--- 
a/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_tags.py
+++ 
b/airflow-core/tests/unit/api_fastapi/core_api/routes/public/test_dag_tags.py
@@ -100,8 +100,8 @@ class TestDagEndpoint:
 
     def _create_dag_tags(self, session=None):
         session.add(DagTag(dag_id=DAG1_ID, name="tag_2"))
-        session.add(DagTag(dag_id=DAG2_ID, name="tag_1"))
         session.add(DagTag(dag_id=DAG3_ID, name="tag_1"))
+        session.add(DagTag(dag_id=DAG3_ID, name="stale_only"))
 
     @pytest.fixture(autouse=True)
     @provide_session
@@ -128,6 +128,7 @@ class TestDagEndpoint:
             params={"foo": 1},
             max_active_tasks=16,
             max_active_runs=16,
+            tags=["tag_1"],
         ):
             EmptyOperator(task_id=TASK_ID)
 
@@ -194,6 +195,12 @@ class TestDagTags(TestDagEndpoint):
                 [],
                 0,
             ),
+            (
+                {"tag_name_pattern": "stale_only"},
+                200,
+                [],
+                0,
+            ),
             (
                 {"tag_name_pattern": "1"},
                 200,

Reply via email to