edwardwang888 opened a new issue #18262:
URL: https://github.com/apache/airflow/issues/18262


   ### Apache Airflow version
   
   main (development)
   
   ### Operating System
   
   OS X (development environment)
   
   ### Versions of Apache Airflow Providers
   
   _No response_
   
   ### Deployment
   
   Other
   
   ### Deployment details
   
   _No response_
   
   ### What happened
   
   1. Here is a DAG with two tasks that are newly added. These task instances 
have not been run yet.
   
![image](https://user-images.githubusercontent.com/40527812/133390015-b2d66698-992a-4af8-a936-1cdf9ae11fc9.png)
   
   1. Clear only the first two task instances.
   
![image](https://user-images.githubusercontent.com/40527812/133389044-548ea2db-b21a-4e13-97b5-c19745d489a6.png)
   
   1. Tree view after clearing.
   
![image](https://user-images.githubusercontent.com/40527812/133389169-60c5eeed-ff45-4507-b091-5547e090bffe.png)
   
   1. Even though only two task instances were cleared, all four task instances 
are executed.
   
![image](https://user-images.githubusercontent.com/40527812/133389748-7b8ee781-b9ba-4e18-a21c-2ba52373376e.png)
   
   
   
   ### What you expected to happen
   
   Only the task instances that were cleared should execute.
   
   ### How to reproduce
   
   Add tasks to a DAG, and then clear any task instance other than the ones 
that were just added. Another way is to add tasks to a DAG that is currently 
running - the newly added task instances will execute (in whichever DAG runs 
are running) once added.
   
   ### Anything else
   
   Based on my observations, I believe this happens because the newly-added 
task instances do not yet exist in the `task_instance` table, so the scheduler 
adds them to the table with state = `NULL` and they get executed. Perhaps this 
could be solved if we only add the task instances to the table if that DAG run 
does not have any existing task instances (new DAG run) or if the DAG run is 
cleared.
   
   ### Are you willing to submit PR?
   
   - [X] 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