amoghrajesh commented on PR #47141:
URL: https://github.com/apache/airflow/pull/47141#issuecomment-2688259771
I think I managed to handle task groups as well.
Example DAG:
```
from airflow import DAG
from airflow.decorators import task, task_group
from datetime import datetime
# Track the results for verification (only for testing purposes)
results = {}
# Expected values for reference
expected_values = {
("tg.t1", 0): ["a", "b"],
("tg.t1", 1): [4],
("tg.t1", 2): ["z"],
("tg.t2", 0): ["a", "b"],
("tg.t2", 1): [4],
("tg.t2", 2): ["z"],
("t3", None): [["a", "b"], [4], ["z"]],
}
# Define the DAG
with DAG(
dag_id="tg_dag",
start_date=datetime(2025, 1, 1),
schedule=None,
catchup=False,
) as dag:
@task
def t(value, ti=None):
# Store results for verification
global results
results[(ti.task_id, ti.map_index)] = value
print("Value is", value)
return value
@task
def t(value, ti=None):
# Store results for verification
global results
results[(ti.task_id, ti.map_index)] = value
print("Value is", value)
return value
@task_group
def tg(va):
# Each expanded group has one t1 and t2 each.
t1 = t.override(task_id="t1")(va)
t2 = t.override(task_id="t2")(t1)
return t2
t2 = tg.expand(va=[["a", "b"], [4], ["z"]])
t3 = t.override(task_id="t3")(t2)
```
Graph vieW:
<img width="861" alt="image"
src="https://github.com/user-attachments/assets/bdb0834c-120a-4f0b-b1d1-71d3b6961458"
/>
Run:
<img width="1213" alt="image"
src="https://github.com/user-attachments/assets/bbce9e21-0d89-4866-8d03-29ebfdb624ff"
/>
XCOM table:
```
8,tg.t1,0,return_value,tg_dag,manual__2025-02-27T15:00:50.382954+00:00_BGTtj5oT,"""[\""a\"",
\""b\""]"""
8,tg.t2,0,return_value,tg_dag,manual__2025-02-27T15:00:50.382954+00:00_BGTtj5oT,"""[\""a\"",
\""b\""]"""
8,tg.t1,1,return_value,tg_dag,manual__2025-02-27T15:00:50.382954+00:00_BGTtj5oT,"""[4]"""
8,tg.t2,1,return_value,tg_dag,manual__2025-02-27T15:00:50.382954+00:00_BGTtj5oT,"""[4]"""
8,tg.t2,2,return_value,tg_dag,manual__2025-02-27T15:00:50.382954+00:00_BGTtj5oT,"""[\""z\""]"""
8,tg.t1,2,return_value,tg_dag,manual__2025-02-27T15:00:50.382954+00:00_BGTtj5oT,"""[\""z\""]"""
```
--
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]