shahar1 commented on issue #40799:
URL: https://github.com/apache/airflow/issues/40799#issuecomment-2663129889

   The wheel turns around, and I just encountered a use case that required this 
feature as well.
   As a follow up to the suggestions above, here's a simplified toy example E2E 
of a possible workaround (suitable for Airflow 2.10.*) - similar to @gdoumenc 
's suggestion, it utilizes an XCom that saves the expanded value, which makes 
it available for the next task to use within `map_index_template`.
   
   ```python
   from airflow.decorators import dag, task_group, task
   from datetime import datetime
   
   from airflow.operators.python import PythonOperator
   
   
   @dag(
       dag_id="dag",
       start_date=datetime(2025, 02, 17),
       catchup=False,
       schedule=None,
   )
   def dag():
       @task_group
       def tg(value: str):
   
           @task
           def get_value(v: str) -> str:
               return v
   
           op = PythonOperator(
               task_id="print_value",
               python_callable=lambda v, **context: print(v),
               map_index_template="{{ 
ti.xcom_pull(task_ids='tg.get_value')[ti.map_index] }}",
               op_kwargs={"v": value}
           )
   
           get_value(v=value) >> op
   
       tg.expand(value=['a','b','c'])
   
   dag()
   ```


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