uranusjr commented on code in PR #36797:
URL: https://github.com/apache/airflow/pull/36797#discussion_r1458454855


##########
airflow/models/taskinstance.py:
##########
@@ -2331,6 +2336,10 @@ def _run_raw_task(
             self.task = self.task.prepare_for_execution()
             context = self.get_template_context(ignore_param_exceptions=False)
 
+            dag = self.task.get_dag()
+            jinja_env = dag.get_template_env(force_sandboxed=True)
+            jinja_env.from_string("map_index_template").render(**context)

Review Comment:
   I want to also move this into `_execute_task` (or 
`_execute_task_with_callbacks`, which calls it), so the rendering can be done 
closer to where the task is actually executed. This also helps us reuse the 
Jinja2 env object instead of having to create it twice (once here and the other 
to render fields on the operator).
   
   If we create a Jinja2 environment in `_execute_task_with_callbacks`, we can 
pass the environment object down into
   
   
https://github.com/apache/airflow/blob/5560a46bfe8a14205c5e8a14f0b5c2ae74ee100c/airflow/models/taskinstance.py#L1571
   
   and then
   
   
https://github.com/apache/airflow/blob/5560a46bfe8a14205c5e8a14f0b5c2ae74ee100c/airflow/models/taskinstance.py#L2194
   
   which already knows to reuse the passed in environment instead of creating a 
new one.
   
   
https://github.com/apache/airflow/blob/5560a46bfe8a14205c5e8a14f0b5c2ae74ee100c/airflow/models/baseoperator.py#L1178-L1192



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