BasPH commented on a change in pull request #5461: [AIRFLOW-4835] Refactor 
render_template
URL: https://github.com/apache/airflow/pull/5461#discussion_r309218376
 
 

 ##########
 File path: airflow/models/taskinstance.py
 ##########
 @@ -1245,21 +1245,20 @@ def overwrite_params_with_dag_run_conf(self, params, 
dag_run):
         if dag_run and dag_run.conf:
             params.update(dag_run.conf)
 
-    def render_templates(self, context=None):
-        task = self.task
+    def render_templates(self, context=None) -> None:
+        """Render templates in the operator fields."""
         if not context:
             context = self.get_template_context()
 
-        if hasattr(self, 'task') and hasattr(self.task, 'dag'):
-            if self.task.dag.user_defined_macros:
-                context.update(self.task.dag.user_defined_macros)
+        if self.task.dag.user_defined_macros:
+            context.update(self.task.dag.user_defined_macros)
 
-        rt = self.task.render_template  # shortcut to method
-        for attr in task.__class__.template_fields:
-            content = getattr(task, attr)
+        # Jinja template all fields in task.template_fields
+        for attr in self.task.template_fields:
+            content = getattr(self.task, attr)
             if content:
-                rendered_content = rt(attr, content, context)
-                setattr(task, attr, rendered_content)
+                rendered_content = self.task.render_template(content, context)
+                setattr(self.task, attr, rendered_content)
 
 Review comment:
   Good point, will move around some code tonight.

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


With regards,
Apache Git Services

Reply via email to