le-chartreux commented on issue #40196:
URL: https://github.com/apache/airflow/issues/40196#issuecomment-2227974096

   Hi,
   
   Yes, it makes sense, thank you @potiuk!
   
   But what if I need to get the result of the final task of a task-group?
   E.g., the following code branches to a task-group (or a task) then get the 
result of the task-group (or the task) that ran.
   But `choose_a_or_b` connects to `operation_on_value` only, as seen on the 
picture below.
   Should I use `return (value, operation_on_value(value))`, even if you said 
it's “really unintuitive and unexpected”?
   
   ```python
   from airflow.decorators import dag, task, task_group
   from airflow.models.baseoperator import BaseOperator
   from airflow.operators.empty import EmptyOperator
   from airflow.utils.trigger_rule import TriggerRule
   from pendulum import datetime
   
   
   @dag(start_date=datetime(2024, 1, 1), schedule=None, catchup=False,)
   def branching_to_first_task_of_group_with_return_value() -> None:
       """Do a branching to a taskflow group and get its result."""
       choice_a_result = choice_a()
       choice_b_result = choice_b()
       choose_a_or_b() >> [choice_a_result, choice_b_result]
   
       get_result(choice_a_result, choice_b_result)
   
   
   @task.branch
   def choose_a_or_b() -> str:
       return "choice_a"
       # return "choice_b"
   
   
   @task_group()
   def choice_a() -> int:
       value = get_a_value()
       return operation_on_value(value)
       # Should I use `return (value, operation_on_value(value))` ?
   
   
   @task
   def get_a_value() -> int:
       return 1
   
   
   @task
   def operation_on_value(value: int) -> int:
       return value * 6
   
   
   @task
   def choice_b() -> int:
       return 2
   
   
   @task(trigger_rule=TriggerRule.NONE_FAILED_MIN_ONE_SUCCESS)
   def get_result(result_a: int | None, result_b: int | None) -> int:
       return result_a or result_b
   
   
   branching_to_first_task_of_group_with_return_value()
   ```
   
   
![Result](https://github.com/user-attachments/assets/004c7b55-f866-4821-a984-6f487ee654d3)
   
   Best regards,
   Nathan


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