kaxil commented on code in PR #53655:
URL: https://github.com/apache/airflow/pull/53655#discussion_r2225405810
##########
airflow-core/src/airflow/api_fastapi/execution_api/routes/dag_runs.py:
##########
@@ -172,16 +177,45 @@ def get_dr_count(
states: Annotated[list[str] | None, Query()] = None,
) -> int:
"""Get the count of DAG runs matching the given criteria."""
- query = select(func.count()).select_from(DagRun).where(DagRun.dag_id ==
dag_id)
+ query =
select(func.count()).select_from(DagRunModel).where(DagRunModel.dag_id ==
dag_id)
if logical_dates:
- query = query.where(DagRun.logical_date.in_(logical_dates))
+ query = query.where(DagRunModel.logical_date.in_(logical_dates))
if run_ids:
- query = query.where(DagRun.run_id.in_(run_ids))
+ query = query.where(DagRunModel.run_id.in_(run_ids))
if states:
- query = query.where(DagRun.state.in_(states))
+ query = query.where(DagRunModel.state.in_(states))
count = session.scalar(query)
return count or 0
+
+
[email protected]("/{dag_id}/previous", status_code=status.HTTP_200_OK)
+def get_previous_dagrun(
+ dag_id: str,
+ logical_date: UtcDateTime,
+ session: SessionDep,
+ state: Annotated[str | None, Query()] = None,
+) -> DagRun | None:
+ """Get the previous DAG run before the given logical date, optionally
filtered by state."""
+ query = (
+ select(DagRunModel)
+ .where(
+ DagRunModel.dag_id == dag_id,
+ DagRunModel.logical_date < logical_date,
+ )
+ .order_by(DagRunModel.logical_date.desc())
+ .limit(1)
+ )
+
+ if state:
Review Comment:
Fixed and added tests
--
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]