Skip to content

Commit

Permalink
AIP-84 Fix dag display name search (apache#42863)
Browse files Browse the repository at this point in the history
* Fix dag display name search

* Fix CI
  • Loading branch information
pierrejeambrun authored and kunaljubce committed Oct 13, 2024
1 parent 4f1a29e commit 3b53e59
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 5 deletions.
12 changes: 12 additions & 0 deletions airflow/models/dag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3046,6 +3046,18 @@ def set_is_paused(self, is_paused: bool, session=NEW_SESSION) -> None:
def dag_display_name(self) -> str:
return self._dag_display_property_value or self.dag_id

@dag_display_name.expression # type: ignore[no-redef]
def dag_display_name(self) -> str:
"""
Expression part of the ``dag_display`` name hybrid property.
:meta private:
"""
return case(
(self._dag_display_property_value.isnot(None), self._dag_display_property_value),
else_=self.dag_id,
)

@classmethod
@internal_api_call
@provide_session
Expand Down
8 changes: 3 additions & 5 deletions tests/api_fastapi/views/public/test_dags.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
DAG1_ID = "test_dag1"
DAG1_DISPLAY_NAME = "display1"
DAG2_ID = "test_dag2"
DAG2_DISPLAY_NAME = "display2"
DAG2_START_DATE = datetime(2021, 6, 15, tzinfo=timezone.utc)
DAG3_ID = "test_dag3"
TASK_ID = "op1"
Expand Down Expand Up @@ -99,7 +98,6 @@ def setup(dag_maker, session=None) -> None:

with dag_maker(
DAG2_ID,
dag_display_name=DAG2_DISPLAY_NAME,
schedule=None,
start_date=DAG2_START_DATE,
doc_md="details",
Expand Down Expand Up @@ -150,7 +148,7 @@ def setup(dag_maker, session=None) -> None:
),
# Search
({"dag_id_pattern": "1"}, 1, [DAG1_ID]),
({"dag_display_name_pattern": "display2"}, 1, [DAG2_ID]),
({"dag_display_name_pattern": "test_dag2"}, 1, [DAG2_ID]),
],
)
def test_get_dags(test_client, query_params, expected_total_entries, expected_ids):
Expand Down Expand Up @@ -239,7 +237,7 @@ def test_patch_dags(test_client, query_params, body, expected_status_code, expec
"query_params, dag_id, expected_status_code, dag_display_name, start_date",
[
({}, "fake_dag_id", 404, "fake_dag", datetime(2023, 12, 31, tzinfo=timezone.utc)),
({}, DAG2_ID, 200, DAG2_DISPLAY_NAME, DAG2_START_DATE),
({}, DAG2_ID, 200, DAG2_ID, DAG2_START_DATE),
],
)
def test_dag_details(test_client, query_params, dag_id, expected_status_code, dag_display_name, start_date):
Expand Down Expand Up @@ -309,7 +307,7 @@ def test_dag_details(test_client, query_params, dag_id, expected_status_code, da
"query_params, dag_id, expected_status_code, dag_display_name",
[
({}, "fake_dag_id", 404, "fake_dag"),
({}, DAG2_ID, 200, DAG2_DISPLAY_NAME),
({}, DAG2_ID, 200, DAG2_ID),
],
)
def test_get_dag(test_client, query_params, dag_id, expected_status_code, dag_display_name):
Expand Down

0 comments on commit 3b53e59

Please sign in to comment.