ed-sparkes opened a new issue, #27913:
URL: https://github.com/apache/airflow/issues/27913

   ### Apache Airflow version
   
   Other Airflow 2 version (please specify below)
   
   ### What happened
   
   Definitely present in Airflow 2.4.2
   
   https://airflow.apache.org/api/v1/dags/{dag_id}/clearTaskInstances
   
   is supposed to return a list of cleared task instances and it used to work 
as expected but some version between 2.3.4 and 2.4.2 the behaviour changed. 
   
   in this file 
`https://github.com/apache/airflow/blob/main/airflow/api_connexion/endpoints/task_instance_endpoint.py`
   
   it appears that something is mutating `task_instances` if not dry run. If i 
run dry run the task_instances are returned, as soon as a i run non dry_run the 
response is always an empty list. 
   
   ```
       task_instances = dag.clear(dry_run=True, 
dag_bag=get_airflow_app().dag_bag, task_ids=task_ids, **data)
       if not dry_run:
           clear_task_instances(
               task_instances.all(),
               session,
               dag=dag,
               dag_run_state=DagRunState.QUEUED if reset_dag_runs else False,
           )
   
       return task_instance_reference_collection_schema.dump(
           TaskInstanceReferenceCollection(task_instances=task_instances.all())
       )
   ```
   
   
   I looked into 
`https://github.com/apache/airflow/blob/main/airflow/models/taskinstance.py` 
where the clear_task_instances function lives, i compared the code between 
2.3.4 and 2.4.2 and the only difference i thought that may cause it is the 
addition of a `    session.flush()` at the end of the method. 
   
   Any thoughts on this would be welcome as we cant upgrade and resolve some 
security dependencies until this is resolved as we rely on the response from 
this api. 
   
   If the `session.flush()` is the culprit, i presume that was added for some 
other reason to resolve some other issue?
   
   
   
   
   ### What you think should happen instead
   
   It should return the cleared tasks as per the documentation
   
   ### How to reproduce
   
   Detail in the What happened section above
   
   ### Operating System
   
   linux
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Official Apache Airflow Helm Chart
   
   ### 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