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.  1. Clear only the first two task instances.  1. Tree view after clearing.  1. Even though only two task instances were cleared, all four task instances are executed.  ### 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]
