Uploaded image for project: 'Apache Airflow'
  1. Apache Airflow
  2. AIRFLOW-5391

Clearing a task skipped by BranchPythonOperator will cause the task to execute

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 1.10.4
    • 2.0.0
    • operators
    • None

    Description

      I tried this on 1.10.3 and 1.10.4, both have this issue: 

      E.g. in this example from the doc, branch_a executed, branch_false was skipped because of branching condition. However if someone Clear branch_false, it'll cause branch_false to execute.

      This behaviour is understandable given how BranchPythonOperator is implemented. BranchPythonOperator does not store its decision anywhere. It skips its own downstream tasks in the branch at runtime. So there's currently no way for branch_false to know it should be skipped without rerunning the branching task.

      This is obviously counter-intuitive from the user's perspective. In this example, users would not expect branch_false to execute when they clear it because the branching task should have skipped it.

      There are a few ways to improve this:

      Option 1): Make downstream tasks skipped by BranchPythonOperator not clearable without also clearing the upstream BranchPythonOperator. In this example, if someone clears branch_false without clearing branching, the Clear action should just fail with an error telling the user he needs to clear the branching task as well.

      Option 2): Make BranchPythonOperator store the result of its skip condition somewhere. Make downstream tasks check for this stored decision and skip themselves if they should have been skipped by the condition. This probably means the decision of BranchPythonOperator needs to be stored in the db.

       

      kevcampb attempted a workaround and on this blog. And he acknowledged his workaround is not perfect and a better permanent fix is needed:

      https://blog.diffractive.io/2018/08/07/replacement-shortcircuitoperator-for-airflow/

       

      Attachments

        Issue Links

          Activity

            People

              yuqian90 Qian Yu
              yuqian90 Qian Yu
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: