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 @@ -28,6 +28,7 @@
AliasGenerator,
ConfigDict,
computed_field,
field_serializer,
field_validator,
)

Expand Down Expand Up @@ -84,6 +85,11 @@ class DAGResponse(BaseModel):
next_dagrun_run_after: datetime | None
owners: list[str]

@field_serializer("tags")
def serialize_tags(self, tags: list[DagTagResponse]) -> list[DagTagResponse]:
"""Sort tags alphabetically by name."""
return sorted(tags, key=lambda tag: tag.name)

@field_validator("owners", mode="before")
@classmethod
def get_owners(cls, v: Any) -> list[str] | None:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1214,6 +1214,33 @@ def test_get_dag(
}
assert res_json == expected

def test_get_dag_tags_sorted_alphabetically(self, session, test_client, dag_maker):
"""Test that tags are returned in alphabetical order for a single DAG."""
dag_id = "test_dag_single_sorted_tags"

# Create a DAG using dag_maker
with dag_maker(dag_id=dag_id, schedule=None):
EmptyOperator(task_id="task1")

dag_maker.sync_dagbag_to_db()

# Add tags in non-alphabetical order
tag_names = ["zebra", "alpha", "mike", "bravo"]
for tag_name in tag_names:
tag = DagTag(name=tag_name, dag_id=dag_id)
session.add(tag)

session.commit()

response = test_client.get(f"/dags/{dag_id}")
assert response.status_code == 200
res_json = response.json()

# Verify tags are sorted alphabetically
tag_names_in_response = [tag["name"] for tag in res_json["tags"]]
expected_sorted_tags = sorted(tag_names)
assert tag_names_in_response == expected_sorted_tags

def test_get_dag_should_response_401(self, unauthenticated_test_client):
response = unauthenticated_test_client.get(f"/dags/{DAG1_ID}")
assert response.status_code == 401
Expand Down
Loading