Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
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,
Expand All @@ -37,7 +37,7 @@
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")

Expand All @@ -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],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,8 @@ def _create_deactivated_paused_dag(self, session=None):

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
Expand All @@ -128,6 +128,7 @@ def setup(self, dag_maker, *, session=None) -> None:
params={"foo": 1},
max_active_tasks=16,
max_active_runs=16,
tags=["tag_1"],
):
EmptyOperator(task_id=TASK_ID)

Expand Down Expand Up @@ -194,6 +195,12 @@ class TestDagTags(TestDagEndpoint):
[],
0,
),
(
{"tag_name_pattern": "stale_only"},
200,
[],
0,
),
(
{"tag_name_pattern": "1"},
200,
Expand Down