raycarter opened a new issue, #40620: URL: https://github.com/apache/airflow/issues/40620
### Apache Airflow version 2.9.2 ### If "Other Airflow 2 version" selected, which one? _No response_ ### What happened? We need to use BranchPythonOperator and dynamic task mapping in a DAG to meet our requirements. The BranchPythonOperator controls whether dynamic mapping is needed, and there is a task (branch_2_task) following the dynamic task mapping that must be executed regardless of whether the dynamic task mapping runs (it can be skipped by receiving an empty list). As shown in the diagram 1, the trigger_rule for branch_2_task needs to be set to none_failed. diagram 1:  If it is set to all_success, the task branch_2_task will also be skipped if the dynamic mapping is skipped due to an empty list (diagram 2). diagram 2:  However, when BranchPythonOperator triggers the branch_1 task, the task branch_2_task on the other branch also gets executed (diagram 3). diagram 3:  The potential bug could be that Airflow does not check if a task is on the executing branch but only checks the trigger_rule. Could you fix this? ### What you think should happen instead? The task branch_2_task has trigger_rule none_failed to be executed even if the dynamic task mapping before it is skipped. If the other branch is executed, the task branch_2_task must be skipped because the branch should be skipped. ### How to reproduce - Airflow 2.9.2 - the demo DAG is here: https://gist.github.com/raycarter/75e896d600adec0563545fc58e3795d2 - use parameters condition1 = 2, mapping_count = 0 to reproduce diagram 1 - use parameters condition1 = 1, mapping_count = 0 to reproduce diagram 3 - change trigger_rule of branch_2_task to all_success, use parameters condition1 = 2, mapping_count = 0 to reproduce diagram 2 ### 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]
