choo121600 commented on code in PR #53216:
URL: https://github.com/apache/airflow/pull/53216#discussion_r2825902766
##########
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py:
##########
@@ -274,17 +274,34 @@ def get_grid_runs(
triggering_user: QueryDagRunTriggeringUserSearch,
) -> list[GridRunsResponse]:
"""Get info about a run for the grid."""
- # Retrieve, sort the previous DAG Runs
- base_query = select(
- DagRun.dag_id,
- DagRun.run_id,
- DagRun.queued_at,
- DagRun.start_date,
- DagRun.end_date,
- DagRun.run_after,
- DagRun.state,
- DagRun.run_type,
- ).where(DagRun.dag_id == dag_id)
+ # get the highest dag_version_number from TIs for each run
+ latest_ti_version = (
+ select(
+ TaskInstance.run_id,
+ func.max(DagVersion.version_number).label("version_number"),
+ )
+ .join(DagVersion, TaskInstance.dag_version_id == DagVersion.id)
+ .where(TaskInstance.dag_id == dag_id)
+ .group_by(TaskInstance.run_id)
+ .subquery()
+ )
Review Comment:
Thanks for pointing that out.
I initially used the subquery approach to avoid N+1 queries, but I agree
that using `DagRun.dag_versions` is more consistent with the public API and
simplifies the logic. I'll update the implementation accordingly.
--
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]