Passing last_dag_run_state to recent dag runs endpoint returns dags where the dag has any dagrun equal to the last_dag_run_state #43882
Labels
area:API
Airflow's REST/HTTP API
area:core
kind:bug
This is a clearly a bug
needs-triage
label for new issues that we didn't triage yet
Apache Airflow version
main (development)
If "Other Airflow 2 version" selected, which one?
No response
What happened?
Passing last_dag_run_state from the UI causes the API to return dags where any of the dagrun might have the state passed and not filtered on the last dag run state. E.g. A dag with one failure among 10 dagruns with last dagrun state as success will be still returned on passing last_dag_run_state=failed in the API.
This can be due to the below query where rank is calculated but on passing last_dag_run_state the row with the rank of 1 which is the latest dag run should be the one considered for filter. Instead the
_LastDagRunStateFilter
only considers state. I am not sure how rank from the subquery can be access here.airflow/airflow/api_fastapi/core_api/routes/ui/dags.py
Lines 67 to 80 in 606ef45
airflow/airflow/api_fastapi/common/parameters.py
Lines 342 to 351 in 606ef45
One idea was to filter by rank=1 and state when last_dag_run_state is passed but that would mean instead of n recent dag runs only 1 run which is the last run will be returned.
airflow/airflow/api_fastapi/core_api/routes/ui/dags.py
Line 87 in 606ef45
Get dags endpoint works though using CTE to return only correct dags :
https://github.com/apache/airflow/blob/main/airflow/api_fastapi/common/db/dags.py
This can be reproduced by the below test where in the fixture dag_1, dag_2 will have last dagrun state as success and dag_3 will have last dagrun state as failed but on passing "success"/"failed" the result remains the same.
airflow/tests/api_fastapi/core_api/routes/ui/test_dags.py
Lines 76 to 77 in 606ef45
What you think should happen instead?
No response
How to reproduce
Operating System
Ubuntu
Versions of Apache Airflow Providers
No response
Deployment
Other
Deployment details
No response
Anything else?
No response
Are you willing to submit PR?
Code of Conduct
The text was updated successfully, but these errors were encountered: