airflow-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [airflow] BasPH commented on a change in pull request #5461: [AIRFLOW-4835] Refactor render_template
Date Sat, 03 Aug 2019 07:39:31 GMT
BasPH commented on a change in pull request #5461: [AIRFLOW-4835] Refactor render_template
URL: https://github.com/apache/airflow/pull/5461#discussion_r310342969
 
 

 ##########
 File path: airflow/models/baseoperator.py
 ##########
 @@ -636,51 +636,71 @@ def __setstate__(self, state):
         self.__dict__ = state
         self._log = logging.getLogger("airflow.task.operators")
 
-    def render_template_from_field(self, attr, content, context, jinja_env):
+    def render_template_fields(self, context: Dict) -> None:
         """
-        Renders a template from a field. If the field is a string, it will
-        simply render the string and return the result. If it is a collection or
-        nested set of collections, it will traverse the structure and render
-        all elements in it. If the field has another type, it will return it as it is.
+        Template all attributes listed in template_fields. Note this operation is irreversible.
+
+        :param context: Dict with values to apply on content
+        :type context: dict
+        """
+        if self.template_fields:
+            if self.dag.user_defined_macros:
+                context.update(self.dag.user_defined_macros)
+
+            for attr_name in self.template_fields:
+                content = getattr(self, attr_name)
+                if content:
+                    rendered_content = self.render_template(content, context)
 
 Review comment:
   Wow that's pretty serious, I missed this one when moving code to the BaseOperator. Thanks
for pointing it out.

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message