tirkarthi opened a new issue, #43882:
URL: https://github.com/apache/airflow/issues/43882

   ### 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.
   
   
https://github.com/apache/airflow/blob/606ef453a1cb3f2c54f90fe756d9044b8edf0121/airflow/api_fastapi/core_api/routes/ui/dags.py#L67-L80
   
   
https://github.com/apache/airflow/blob/606ef453a1cb3f2c54f90fe756d9044b8edf0121/airflow/api_fastapi/common/parameters.py#L342-L351
   
   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.
   
   
https://github.com/apache/airflow/blob/606ef453a1cb3f2c54f90fe756d9044b8edf0121/airflow/api_fastapi/core_api/routes/ui/dags.py#L87
   
   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.
   
   
https://github.com/apache/airflow/blob/606ef453a1cb3f2c54f90fe756d9044b8edf0121/tests/api_fastapi/core_api/routes/ui/test_dags.py#L76-L77
   
   ### What you think should happen instead?
   
   _No response_
   
   ### How to reproduce
   
   1. Dag1 with 5 dagruns and last run as success but 3rd run as failed.
   2. Dag 2 with 5 dagruns and last run as 
failhttps://github.com/apache/airflow/blob/main/airflow/api_fastapi/common/db/dags.pyed.
   3. Go to http://localhost:8000/webapp/dags?last_dag_run_state=failed and in 
the recent dag runs API Dag1 is still returned but filtered out in the frontend.
   
   ### 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?
   
   - [ ] Yes I am willing to submit a PR!
   
   ### Code of Conduct
   
   - [X] I agree to follow this project's [Code of 
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
   


-- 
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]

Reply via email to