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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to