From 9355215325c91e1b43cc29fd7865ee5349ce5221 Mon Sep 17 00:00:00 2001 From: Adrian Bridgett Date: Tue, 12 Apr 2016 09:25:51 +0100 Subject: [PATCH] Ensure attr is in scope for error message During the recursion work below 'attr' dropped out of scope: https://github.com/airbnb/airflow/commit/376cdd4556f4b46ec50acc5cfc324a3fad6c51f3 This commit ensures attr is in scope once more as it's very helpful in tracing problems. --- airflow/models.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/airflow/models.py b/airflow/models.py index 92e82267fd298..929b921f0451d 100644 --- a/airflow/models.py +++ b/airflow/models.py @@ -1329,7 +1329,7 @@ def render_templates(self): for attr in task.__class__.template_fields: content = getattr(task, attr) if content: - rendered_content = rt(content, jinja_context) + rendered_content = rt(attr, content, jinja_context) setattr(task, attr, rendered_content) def email_alert(self, exception, is_retry=False): @@ -1809,7 +1809,7 @@ def __deepcopy__(self, memo): result.user_defined_macros = self.user_defined_macros return result - def render_template_from_field(self, content, context, jinja_env): + def render_template_from_field(self, attr, content, context, jinja_env): ''' 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 @@ -1820,10 +1820,10 @@ def render_template_from_field(self, content, context, jinja_env): if isinstance(content, six.string_types): result = jinja_env.from_string(content).render(**context) elif isinstance(content, (list, tuple)): - result = [rt(e, context) for e in content] + result = [rt(attr, e, context) for e in content] elif isinstance(content, dict): result = { - k: rt(v, context) + k: rt("{}[{}]".format(attr, k), v, context) for k, v in list(content.items())} else: param_type = type(content) @@ -1833,7 +1833,7 @@ def render_template_from_field(self, content, context, jinja_env): raise AirflowException(msg) return result - def render_template(self, content, context): + def render_template(self, attr, content, context): ''' Renders a template either from a file or directly in a field, and returns the rendered result. @@ -1848,7 +1848,7 @@ def render_template(self, content, context): any([content.endswith(ext) for ext in exts])): return jinja_env.get_template(content).render(**context) else: - return self.render_template_from_field(content, context, jinja_env) + return self.render_template_from_field(attr, content, context, jinja_env) def prepare_template(self): '''