uranusjr commented on code in PR #53357: URL: https://github.com/apache/airflow/pull/53357#discussion_r2493635974
########## airflow-core/src/airflow/api_fastapi/execution_api/routes/dag_runs.py: ########## @@ -41,6 +44,86 @@ log = logging.getLogger(__name__) [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[DagRunState | 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: + query = query.where(DagRunModel.state == state) + + dag_run = session.scalar(query) + + if not dag_run: + return None + + return DagRun.model_validate(dag_run) Review Comment: Is this simply moved from below? Please move it back so the PR is easier to review. -- 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]
