tirkarthi commented on PR #53429:
URL: https://github.com/apache/airflow/pull/53429#issuecomment-3086642262
> But personally, I am not really sure it's worth the trade off -- coupling
in exchange for fewer endpoints. Like, what's the problem with adding an
endpoint for this?
I am not against adding new endpoints specific to UI since they are not
public and can change with compatibility concerns. My point was along both the
function in the PR and the existing one are doing similar things except the
current one is missing date fields which could be added to reuse it. The
drawback is that it will add additional fields to the refresh response i.e.In
example dag it increases from 260 bytes to 390 bytes for `get_latest_run` with
additional fields.
PR
```python
def get_latest_run_info(dag_id: str, session: SessionDep) ->
list[DAGRunLightResponse]:
"""Get latest run."""
if dag_id == "~":
raise HTTPException(
status.HTTP_400_BAD_REQUEST,
"`~` was supplied as dag_id, but querying multiple dags is not
supported.",
)
query = (
select(DagRun)
.where(DagRun.dag_id == dag_id)
.order_by(DagRun.run_after.desc())
.limit(1)
.options(
load_only(
DagRun.dag_id,
DagRun.run_id,
DagRun.end_date,
DagRun.logical_date,
DagRun.run_after,
DagRun.start_date,
DagRun.state,
)
)
)
dag_runs = session.scalars(query)
return dag_runs
```
airflow-core/src/airflow/api_fastapi/core_api/routes/ui/grid.py
```python
def get_latest_run(
dag_id: str,
session: SessionDep,
) -> LatestRunResponse | None:
"""
Get information about the latest dag run by run_after.
This is used by the UI to figure out if it needs to rerun queries and
resume auto refresh.
"""
return session.execute(
select(
DagRun.id,
DagRun.dag_id,
DagRun.run_id,
DagRun.run_after,
)
.where(DagRun.dag_id == dag_id)
.order_by(DagRun.run_after.desc())
.limit(1)
).one_or_none()
```
--
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]