You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "rawwar (via GitHub)" <gi...@apache.org> on 2024/10/30 10:23:32 UTC

[PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

rawwar opened a new pull request, #43506:
URL: https://github.com/apache/airflow/pull/43506

   related to https://github.com/apache/airflow/issues/42701


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43506:
URL: https://github.com/apache/airflow/pull/43506#discussion_r1849848177


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -229,3 +238,65 @@ def clear_dag_run(
         )
         dag_run_cleared = session.scalar(select(DagRun).where(DagRun.id == dag_run.id))
         return DAGRunResponse.model_validate(dag_run_cleared, from_attributes=True)
+
+
+@dag_run_router.get("", responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]))
+def get_dag_runs(
+    dag_id: str,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    logical_date: Annotated[RangeFilter, Depends(datetime_range_filter_factory("logical_date", DagRun))],
+    start_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("start_date", DagRun))],
+    end_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("end_date", DagRun))],
+    update_at_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("updated_at", DagRun))],
+    state: QueryDagRunStateFilter,
+    order_by: Annotated[
+        SortParam,
+        Depends(
+            SortParam(
+                [
+                    "id",
+                    "state",
+                    "dag_id",
+                    "logical_date",
+                    "dag_run_id",
+                    "start_date",
+                    "end_date",
+                    "updated_at",
+                    "external_trigger",
+                    "conf",
+                ],
+                DagRun,
+            ).dynamic_depends(default="id")
+        ),
+    ],
+    session: Annotated[Session, Depends(get_session)],
+    request: Request,
+) -> DAGRunCollectionResponse:
+    """
+    Get all DAG Runs.
+
+    This endpoint allows specifying `~` as the dag_id to retrieve Dag Runs for all DAGs.
+    """
+    if dag_id != "~":
+        dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
+        if not dag:
+            raise HTTPException(status.HTTP_404_NOT_FOUND, f"The DAG with dag_id: `{dag_id}` was not found")
+    base_query = select(DagRun)

Review Comment:
   You can put this above the first if, so we then merged the two `if dag_id != "~"` code blocks. Avoiding checking two times the conditions.



##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -229,3 +238,65 @@ def clear_dag_run(
         )
         dag_run_cleared = session.scalar(select(DagRun).where(DagRun.id == dag_run.id))
         return DAGRunResponse.model_validate(dag_run_cleared, from_attributes=True)
+
+
+@dag_run_router.get("", responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]))
+def get_dag_runs(
+    dag_id: str,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    logical_date: Annotated[RangeFilter, Depends(datetime_range_filter_factory("logical_date", DagRun))],
+    start_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("start_date", DagRun))],
+    end_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("end_date", DagRun))],
+    update_at_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("updated_at", DagRun))],
+    state: QueryDagRunStateFilter,
+    order_by: Annotated[
+        SortParam,
+        Depends(
+            SortParam(
+                [
+                    "id",
+                    "state",
+                    "dag_id",
+                    "logical_date",
+                    "dag_run_id",
+                    "start_date",
+                    "end_date",
+                    "updated_at",
+                    "external_trigger",
+                    "conf",
+                ],
+                DagRun,
+            ).dynamic_depends(default="id")
+        ),
+    ],
+    session: Annotated[Session, Depends(get_session)],
+    request: Request,
+) -> DAGRunCollectionResponse:
+    """
+    Get all DAG Runs.
+
+    This endpoint allows specifying `~` as the dag_id to retrieve Dag Runs for all DAGs.
+    """
+    if dag_id != "~":
+        dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
+        if not dag:
+            raise HTTPException(status.HTTP_404_NOT_FOUND, f"The DAG with dag_id: `{dag_id}` was not found")
+    base_query = select(DagRun)

Review Comment:
   You can put this above the first if, so we then merged the two `if dag_id != "~"` code blocks. Avoiding checking two times the conditions.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "rawwar (via GitHub)" <gi...@apache.org>.
rawwar commented on code in PR #43506:
URL: https://github.com/apache/airflow/pull/43506#discussion_r1835279277


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -147,3 +156,70 @@ def patch_dag_run(
     dag_run = session.get(DagRun, dag_run.id)
 
     return DAGRunResponse.model_validate(dag_run, from_attributes=True)
+
+
+@dag_run_router.get("/", responses=create_openapi_http_exception_doc([401]))
+async def get_dag_runs(
+    dag_id: str,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    logical_date: Annotated[
+        RangeFilter, Depends(datetime_range_filter_factory("logical_date", DagRun, "execution_date"))
+    ],
+    start_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("start_date", DagRun))],
+    end_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("end_date", DagRun))],
+    update_at_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("updated_at", DagRun))],
+    state: QueryDagRunStateFilter,
+    order_by: Annotated[
+        SortParam,
+        Depends(
+            SortParam(
+                [
+                    "id",
+                    "state",
+                    "dag_id",
+                    "execution_date",
+                    "dag_run_id",
+                    "start_date",
+                    "end_date",
+                    "updated_at",
+                    "external_trigger",
+                    "conf",
+                ],
+                DagRun,
+            ).dynamic_depends(default="id")
+        ),
+    ],
+    session: Annotated[Session, Depends(get_session)],
+    # fields: list[str] | None = Query(None),

Review Comment:
   @pierrejeambrun, @bugraoz93 , looking for ideas on how to implement fields to return.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on PR #43506:
URL: https://github.com/apache/airflow/pull/43506#issuecomment-2482730997

   > @pierrejeambrun , as of now get dag runs does not raise 404 not found if dag id is invalid. [Link](https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html#operation/get_dag_runs).
   
   > Should we update it?
   
   I think we should `get_tasks` ?:
   ```python
       """Get tasks for DAG."""
       dag: DAG = request.app.state.dag_bag.get_dag(dag_id)
       if not dag:
           raise HTTPException(status.HTTP_404_NOT_FOUND, f"Dag with id {dag_id} was not found")
   ```
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun commented on code in PR #43506:
URL: https://github.com/apache/airflow/pull/43506#discussion_r1842191722


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -147,3 +156,70 @@ def patch_dag_run(
     dag_run = session.get(DagRun, dag_run.id)
 
     return DAGRunResponse.model_validate(dag_run, from_attributes=True)
+
+
+@dag_run_router.get("/", responses=create_openapi_http_exception_doc([401]))
+async def get_dag_runs(
+    dag_id: str,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    logical_date: Annotated[
+        RangeFilter, Depends(datetime_range_filter_factory("logical_date", DagRun, "execution_date"))
+    ],
+    start_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("start_date", DagRun))],
+    end_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("end_date", DagRun))],
+    update_at_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("updated_at", DagRun))],
+    state: QueryDagRunStateFilter,
+    order_by: Annotated[
+        SortParam,
+        Depends(
+            SortParam(
+                [
+                    "id",
+                    "state",
+                    "dag_id",
+                    "execution_date",
+                    "dag_run_id",
+                    "start_date",
+                    "end_date",
+                    "updated_at",
+                    "external_trigger",
+                    "conf",
+                ],
+                DagRun,
+            ).dynamic_depends(default="id")
+        ),
+    ],
+    session: Annotated[Session, Depends(get_session)],
+    # fields: list[str] | None = Query(None),

Review Comment:
   For now you can just skip `fields`. Because it's an issue to implement and dynamically change the returned type. (sub fields etc...), which isn't great for the client.
   
   This is mentioned here https://github.com/apache/airflow/issues/43378#issue-2613951437, as one of the breaking change.
   
   We can either fix that later before 3.0 release, or accept that breaking change. In the mean time I would suggest to just remove it and don't bother with it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "rawwar (via GitHub)" <gi...@apache.org>.
rawwar closed pull request #43506: AIP-84 Migrate GET Dag Runs endpoint to FastAPI
URL: https://github.com/apache/airflow/pull/43506


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "rawwar (via GitHub)" <gi...@apache.org>.
rawwar commented on PR #43506:
URL: https://github.com/apache/airflow/pull/43506#issuecomment-2480547709

   @pierrejeambrun , as of now get dag runs does not raise 404 not found if dag id is invalid. [Link](https://airflow.apache.org/docs/apache-airflow/stable/stable-rest-api-ref.html#operation/get_dags).
   
   Should we update it?


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "rawwar (via GitHub)" <gi...@apache.org>.
rawwar commented on code in PR #43506:
URL: https://github.com/apache/airflow/pull/43506#discussion_r1847117275


##########
tests/api_fastapi/core_api/routes/public/test_dag_run.py:
##########
@@ -156,6 +164,275 @@ def test_get_dag_run_not_found(self, test_client):
         assert body["detail"] == "The DagRun with dag_id: `test_dag1` and run_id: `invalid` was not found"
 
 
+class TestGetDagRuns:
+    @staticmethod
+    def parse_datetime(datetime_str):
+        return datetime_str.isoformat().replace("+00:00", "Z") if datetime_str else None
+
+    @staticmethod
+    def get_dag_run_dict(run: DagRun):
+        return {
+            "run_id": run.run_id,
+            "dag_id": run.dag_id,
+            "logical_date": TestGetDagRuns.parse_datetime(run.logical_date),
+            "queued_at": TestGetDagRuns.parse_datetime(run.queued_at),
+            "start_date": TestGetDagRuns.parse_datetime(run.start_date),
+            "end_date": TestGetDagRuns.parse_datetime(run.end_date),
+            "data_interval_start": TestGetDagRuns.parse_datetime(run.data_interval_start),
+            "data_interval_end": TestGetDagRuns.parse_datetime(run.data_interval_end),
+            "last_scheduling_decision": TestGetDagRuns.parse_datetime(run.last_scheduling_decision),
+            "run_type": run.run_type,
+            "state": run.state,
+            "external_trigger": run.external_trigger,
+            "triggered_by": run.triggered_by.value,
+            "conf": run.conf,
+            "note": run.note,
+        }
+
+    @pytest.mark.parametrize("dag_id, total_entries", [(DAG1_ID, 2), (DAG2_ID, 2), ("~", 4)])
+    def test_get_dag_runs(self, test_client, session, dag_id, total_entries):
+        response = test_client.get(f"/public/dags/{dag_id}/dagRuns")
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == total_entries
+        for each in body["dag_runs"]:
+            run = (
+                session.query(DagRun)
+                .where(DagRun.dag_id == each["dag_id"], DagRun.run_id == each["run_id"])
+                .one()
+            )
+            expected = self.get_dag_run_dict(run)
+            assert each == expected
+
+    def test_get_dag_runs_not_found(self, test_client):
+        response = test_client.get("/public/dags/invalid/dagRuns")
+        assert response.status_code == 404
+        body = response.json()
+        assert body["detail"] == "The DAG with dag_id: `invalid` was not found"
+
+    def test_invalid_order_by_raises_400(self, test_client):
+        response = test_client.get("/public/dags/test_dag1/dagRuns?order_by=invalid")
+        assert response.status_code == 400
+        body = response.json()
+        assert (
+            body["detail"]
+            == "Ordering with 'invalid' is disallowed or the attribute does not exist on the model"
+        )
+
+    @pytest.mark.parametrize(
+        "order_by, expected_dag_id_order",
+        [
+            ("id", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("state", [DAG1_RUN2_ID, DAG1_RUN1_ID]),
+            ("dag_id", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("logical_date", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("dag_run_id", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("start_date", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("end_date", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("updated_at", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("external_trigger", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ("conf", [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+        ],
+    )
+    def test_return_correct_results_with_order_by(self, test_client, order_by, expected_dag_id_order):
+        response = test_client.get("/public/dags/test_dag1/dagRuns", params={"order_by": order_by})
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == 2
+        assert [each["run_id"] for each in body["dag_runs"]] == expected_dag_id_order
+
+    @pytest.mark.parametrize(
+        "query_params, expected_dag_id_order",
+        [
+            ({}, [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ({"limit": 1}, [DAG1_RUN1_ID]),
+            ({"limit": 3}, [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            ({"offset": 1}, [DAG1_RUN2_ID]),
+            ({"offset": 2}, []),
+            ({"limit": 1, "offset": 1}, [DAG1_RUN2_ID]),
+            ({"limit": 1, "offset": 2}, []),
+        ],
+    )
+    def test_limit_and_offset(self, test_client, query_params, expected_dag_id_order):
+        response = test_client.get("/public/dags/test_dag1/dagRuns", params=query_params)
+        assert response.status_code == 200
+        body = response.json()
+        assert body["total_entries"] == 2
+        assert [each["run_id"] for each in body["dag_runs"]] == expected_dag_id_order
+
+    @pytest.mark.parametrize(
+        "query_params, expected_detail",
+        [
+            (
+                {"limit": 1, "offset": -1},
+                [
+                    {
+                        "type": "greater_than_equal",
+                        "loc": ["query", "offset"],
+                        "msg": "Input should be greater than or equal to 0",
+                        "input": "-1",
+                        "ctx": {"ge": 0},
+                    }
+                ],
+            ),
+            (
+                {"limit": -1, "offset": 1},
+                [
+                    {
+                        "type": "greater_than_equal",
+                        "loc": ["query", "limit"],
+                        "msg": "Input should be greater than or equal to 0",
+                        "input": "-1",
+                        "ctx": {"ge": 0},
+                    }
+                ],
+            ),
+            (
+                {"limit": -1, "offset": -1},
+                [
+                    {
+                        "type": "greater_than_equal",
+                        "loc": ["query", "limit"],
+                        "msg": "Input should be greater than or equal to 0",
+                        "input": "-1",
+                        "ctx": {"ge": 0},
+                    },
+                    {
+                        "type": "greater_than_equal",
+                        "loc": ["query", "offset"],
+                        "msg": "Input should be greater than or equal to 0",
+                        "input": "-1",
+                        "ctx": {"ge": 0},
+                    },
+                ],
+            ),
+        ],
+    )
+    def test_bad_limit_and_offset(self, test_client, query_params, expected_detail):
+        response = test_client.get("/public/dags/test_dag1/dagRuns", params=query_params)
+        assert response.status_code == 422
+        assert response.json()["detail"] == expected_detail
+
+    @pytest.mark.parametrize(
+        "dag_id, query_params, expected_dag_id_list",
+        [
+            (DAG1_ID, {"logical_date_gte": LOGICAL_DATE1.isoformat()}, [DAG1_RUN1_ID, DAG1_RUN2_ID]),
+            (DAG2_ID, {"logical_date_lte": LOGICAL_DATE3.isoformat()}, [DAG2_RUN1_ID]),
+            (
+                "~",
+                {
+                    "start_date_gte": START_DATE1.isoformat(),
+                    "start_date_lte": (START_DATE2 - timedelta(days=1)).isoformat(),
+                },
+                [DAG1_RUN1_ID, DAG1_RUN2_ID],
+            ),
+            (
+                DAG1_ID,
+                {
+                    "end_date_gte": START_DATE2.isoformat(),
+                    "end_date_lte": (datetime.now(tz=timezone.utc) + timedelta(days=1)).isoformat(),
+                },
+                [DAG1_RUN1_ID, DAG1_RUN2_ID],
+            ),
+            (
+                DAG1_ID,
+                {
+                    "logical_date_gte": LOGICAL_DATE1.isoformat(),
+                    "logical_date_lte": LOGICAL_DATE2.isoformat(),
+                },
+                [DAG1_RUN1_ID, DAG1_RUN2_ID],
+            ),
+            (
+                DAG2_ID,
+                {
+                    "start_date_gte": START_DATE2.isoformat(),
+                    "end_date_lte": (datetime.now(tz=timezone.utc) + timedelta(days=1)).isoformat(),
+                },
+                [DAG2_RUN1_ID, DAG2_RUN2_ID],
+            ),
+            (DAG1_ID, {"state": DagRunState.SUCCESS.value}, [DAG1_RUN1_ID]),
+            (DAG2_ID, {"state": DagRunState.FAILED.value}, []),
+            (
+                DAG1_ID,
+                {"state": DagRunState.SUCCESS.value, "logical_date_gte": LOGICAL_DATE1.isoformat()},
+                [DAG1_RUN1_ID],
+            ),
+            (
+                DAG1_ID,
+                {"state": DagRunState.FAILED.value, "start_date_gte": START_DATE1.isoformat()},
+                [DAG1_RUN2_ID],
+            ),
+        ],
+    )
+    def test_filters(self, test_client, dag_id, query_params, expected_dag_id_list):
+        response = test_client.get(f"/public/dags/{dag_id}/dagRuns", params=query_params)
+        assert response.status_code == 200
+        body = response.json()
+        assert [each["run_id"] for each in body["dag_runs"]] == expected_dag_id_list
+
+    def test_bad_filters(self, test_client):
+        query_params = {
+            "logical_date_gte": "invalid",
+            "start_date_gte": "invalid",
+            "end_date_gte": "invalid",
+            "logical_date_lte": "invalid",
+            "start_date_lte": "invalid",
+            "end_date_lte": "invalid",
+        }
+        expected_detail = [
+            {
+                "type": "datetime_from_date_parsing",
+                "loc": ["query", "logical_date_gte"],
+                "msg": "Input should be a valid datetime or date, input is too short",
+                "input": "invalid",
+                "ctx": {"error": "input is too short"},
+            },
+            {
+                "type": "datetime_from_date_parsing",
+                "loc": ["query", "logical_date_lte"],
+                "msg": "Input should be a valid datetime or date, input is too short",
+                "input": "invalid",
+                "ctx": {"error": "input is too short"},
+            },
+            {
+                "type": "datetime_from_date_parsing",
+                "loc": ["query", "start_date_gte"],
+                "msg": "Input should be a valid datetime or date, input is too short",
+                "input": "invalid",
+                "ctx": {"error": "input is too short"},
+            },
+            {
+                "type": "datetime_from_date_parsing",
+                "loc": ["query", "start_date_lte"],
+                "msg": "Input should be a valid datetime or date, input is too short",
+                "input": "invalid",
+                "ctx": {"error": "input is too short"},
+            },
+            {
+                "type": "datetime_from_date_parsing",
+                "loc": ["query", "end_date_gte"],
+                "msg": "Input should be a valid datetime or date, input is too short",
+                "input": "invalid",
+                "ctx": {"error": "input is too short"},
+            },
+            {
+                "type": "datetime_from_date_parsing",
+                "loc": ["query", "end_date_lte"],
+                "msg": "Input should be a valid datetime or date, input is too short",
+                "input": "invalid",
+                "ctx": {"error": "input is too short"},
+            },
+        ]
+        response = test_client.get(f"/public/dags/{DAG1_ID}/dagRuns", params=query_params)
+        assert response.status_code == 422
+        body = response.json()
+        assert body["detail"] == expected_detail
+
+    def test_invalid_state(self, test_client):
+        with pytest.raises(ValueError, match="'invalid' is not a valid DagRunState"):

Review Comment:
   I checked this for List TI endpoint and its same. It raises a ValueError. So, I kept it the same. But, wondering if this should raise 422



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "bugraoz93 (via GitHub)" <gi...@apache.org>.
bugraoz93 commented on code in PR #43506:
URL: https://github.com/apache/airflow/pull/43506#discussion_r1835512233


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -147,3 +156,70 @@ def patch_dag_run(
     dag_run = session.get(DagRun, dag_run.id)
 
     return DAGRunResponse.model_validate(dag_run, from_attributes=True)
+
+
+@dag_run_router.get("/", responses=create_openapi_http_exception_doc([401]))
+async def get_dag_runs(
+    dag_id: str,
+    limit: QueryLimit,
+    offset: QueryOffset,
+    logical_date: Annotated[
+        RangeFilter, Depends(datetime_range_filter_factory("logical_date", DagRun, "execution_date"))
+    ],
+    start_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("start_date", DagRun))],
+    end_date_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("end_date", DagRun))],
+    update_at_range: Annotated[RangeFilter, Depends(datetime_range_filter_factory("updated_at", DagRun))],
+    state: QueryDagRunStateFilter,
+    order_by: Annotated[
+        SortParam,
+        Depends(
+            SortParam(
+                [
+                    "id",
+                    "state",
+                    "dag_id",
+                    "execution_date",
+                    "dag_run_id",
+                    "start_date",
+                    "end_date",
+                    "updated_at",
+                    "external_trigger",
+                    "conf",
+                ],
+                DagRun,
+            ).dynamic_depends(default="id")
+        ),
+    ],
+    session: Annotated[Session, Depends(get_session)],
+    # fields: list[str] | None = Query(None),

Review Comment:
   Due to its type and purpose, this should be similar to `update_mask` (even though it is reversed regarding `masking`).  We will get in `explode=true`, similar to update_mask again `....?fields=item1&fields=item2`. 
   
   As far as I see there isn't a way to exclude fields during `validation` and doing `dump` and `validate` won't work until we have a dynamically generated `Pydantic` model with the selected fields making the validation on return. I saw a discussion about including this capability. There are also some workarounds for people there. Maybe we can also have a generic exclusion method for `Pydantic` models until it is provided fully.
   https://github.com/pydantic/pydantic/issues/9573



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "rawwar (via GitHub)" <gi...@apache.org>.
rawwar commented on code in PR #43506:
URL: https://github.com/apache/airflow/pull/43506#discussion_r1847212320


##########
airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -228,3 +237,65 @@ def clear_dag_run(
         )
         dag_run_cleared = session.scalar(select(DagRun).where(DagRun.id == dag_run.id))
         return DAGRunResponse.model_validate(dag_run_cleared, from_attributes=True)
+
+
+@dag_run_router.get("")

Review Comment:
   ```suggestion
   @dag_run_router.get("", responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]))
   ```



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] AIP-84 Migrate GET Dag Runs endpoint to FastAPI [airflow]

Posted by "pierrejeambrun (via GitHub)" <gi...@apache.org>.
pierrejeambrun merged PR #43506:
URL: https://github.com/apache/airflow/pull/43506


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org