yuqian90 commented on issue #10725:
URL: https://github.com/apache/airflow/issues/10725#issuecomment-687183058


   Thanks for bringing this up. Definitely looks related to 
https://github.com/apache/airflow/pull/7276. 
   
   Let me clarify the problem first. @CatarinaSilva 's example looks like this. 
The expected end state should be both `extra_task` and `final_task` are in 
success. But the actual behaviour looks like this.  `extra_task` is success, 
`final_task` is skipped.
   
   
![image](https://user-images.githubusercontent.com/6637585/92248893-e9817980-eefb-11ea-9304-b7a5b762b97d.png)
   
   
   I'm sorry that I did not anticipate empty branch cases when working on 
https://github.com/apache/airflow/pull/7276. That said, if we actually look at 
the docstr of `BranchPythonOperator`, it says this:
   ```
       ... expects a Python function that returns
       a single task_id or list of task_ids to follow. The task_id(s) returned
       should point to a task directly downstream from {self}. All other 
"branches"
       or directly downstream tasks are marked with a state of ``skipped`` so 
that
       these paths can't move forward.
   ```
   
   In this case, both `extra_task` and `final_task` are directly downstream of 
`branch_task`. Its `python_callable` returned `extra_task`. So it now 
faithfully does what its docstr said, follow `extra_task` and skip the others.
   
   I understand this sounds counter-intuitive. The problem is 
`NotPreviouslySkippedDep` tells Airflow `final_task` should be skipped because 
it is directly downstream of a `BranchPythonOperator` that decided to follow 
another branch. At the same time, `TriggerRuleDep` says that `final_task` can 
be run because its trigger_rule `none_failed_or_skipped` is satisfied.
   
   To remove this ambiguity, may I suggest changing the last line to this, i.e. 
don't put `final_op` directly downstream of `BranchPythonOperator`.
   
   ```
       final_op.set_upstream(extra_op)
   ```
   The DAG will then look like this and the behaviour will be as expected:
   
   
![image](https://user-images.githubusercontent.com/6637585/92250704-5eee4980-eefe-11ea-8754-d1fdd66f1e21.png)
   
   
   
   If this solution is not satisfactory, please let me know and I'll think 
about something better.


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to