Skip to content

Commit

Permalink
Merge pull request #1351 from abridgett/feature/correct_render_error
Browse files Browse the repository at this point in the history
Ensure attr is in scope for error message
  • Loading branch information
bolkedebruin committed Apr 12, 2016
2 parents 753cc15 + 9355215 commit f8d19b4
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions airflow/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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.
Expand All @@ -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):
'''
Expand Down

0 comments on commit f8d19b4

Please sign in to comment.