jason810496 commented on code in PR #56406:
URL: https://github.com/apache/airflow/pull/56406#discussion_r2572826069
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -93,6 +95,51 @@
dag_run_router = AirflowRouter(tags=["DagRun"],
prefix="/dags/{dag_id}/dagRuns")
+@dag_run_router.get(
+ "/recent-configurations",
+ responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+ dependencies=[Depends(requires_access_dag(method="GET",
access_entity=DagAccessEntity.RUN))],
+)
+def get_recent_dag_run_configurations(
+ dag_id: str,
+ session: SessionDep,
+ dag_bag: DagBagDep,
+ limit: Annotated[int, Query(ge=1, le=50, description="Maximum number of
recent configurations to return")] = 5,
+) -> RecentConfigurationsResponse:
+ """Get recent manual DAG run configurations for a specific DAG."""
+ # Check if the DAG exists
+ get_latest_version_of_dag(dag_bag, dag_id, session)
+
+ # Get the configured limit from settings
+ configured_limit = conf.getint("webserver",
"num_recent_configurations_for_trigger", fallback=5)
+ actual_limit = min(limit, configured_limit)
+
+ # Query recent manual DAG runs with configurations
+ query = (
+ select(DagRun.run_id, DagRun.conf, DagRun.logical_date,
DagRun.start_date)
+ .where(
+ DagRun.dag_id == dag_id,
+ DagRun.run_type == DagRunType.MANUAL,
+ DagRun.conf.is_not(None)
+ )
+ .order_by(DagRun.start_date.desc())
+ .limit(actual_limit)
+ )
+
+ results = session.execute(query).all()
+
+ configurations = []
+ for result in results:
+ configurations.append({
+ "run_id": result.run_id,
+ "conf": result.conf,
+ "logical_date": result.logical_date,
+ "start_date": result.start_date,
+ })
+
+ return RecentConfigurationsResponse(configurations=configurations)
Review Comment:
```suggestion
configurations = session.scalars(query)
return RecentConfigurationsResponse(configurations=configurations)
```
##########
airflow-core/src/airflow/api_fastapi/core_api/datamodels/dag_run.py:
##########
@@ -182,3 +182,18 @@ class DAGRunsBatchBody(StrictBaseModel):
duration_lt: float | None = None
conf_contains: str | None = None
+
+
+class RecentConfigurationResponse(BaseModel):
+ """Response model for recent DAG run configurations."""
+
+ run_id: str = Field(description="The run ID of the DAG run")
+ conf: dict | None = Field(description="The configuration used for this DAG
run")
+ logical_date: AwareDatetime | None = Field(description="The logical date
of the DAG run")
+ start_date: AwareDatetime | None = Field(description="The start date of
the DAG run")
+
+
+class RecentConfigurationsResponse(BaseModel):
+ """Response model for recent DAG run configurations collection."""
+
+ configurations: list[RecentConfigurationResponse] =
Field(description="List of recent configurations")
Review Comment:
```suggestion
class RecentConfigurationsCollectionResponse(BaseModel):
"""Response model for recent DAG run configurations collection."""
configurations: Iterable[RecentConfigurationResponse]
```
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/public/dag_run.py:
##########
@@ -93,6 +95,51 @@
dag_run_router = AirflowRouter(tags=["DagRun"],
prefix="/dags/{dag_id}/dagRuns")
+@dag_run_router.get(
+ "/recent-configurations",
+ responses=create_openapi_http_exception_doc([status.HTTP_404_NOT_FOUND]),
+ dependencies=[Depends(requires_access_dag(method="GET",
access_entity=DagAccessEntity.RUN))],
+)
Review Comment:
`airflow-core/src/airflow/api_fastapi/core_api/routes/ui/dag_run.py` might
be a better place for this route.
--
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]