uranusjr commented on a change in pull request #21054:
URL: https://github.com/apache/airflow/pull/21054#discussion_r790425035
##########
File path: airflow/models/baseoperator.py
##########
@@ -1085,10 +1095,16 @@ def _do_render_template_fields(
seen_oids: Set,
) -> None:
for attr_name in template_fields:
- content = getattr(parent, attr_name)
- if content:
- rendered_content = self.render_template(content, context,
jinja_env, seen_oids)
- setattr(parent, attr_name, rendered_content)
+ if hasattr(parent, attr_name):
+ content = getattr(parent, attr_name)
+ if content:
+ rendered_content = self.render_template(content, context,
jinja_env, seen_oids)
+ setattr(parent, attr_name, rendered_content)
+ else:
+ raise AttributeError(
+ f"{attr_name!r} is configured as a template field "
+ f"but {parent.task_type} does not have this attribute."
+ )
Review comment:
```suggestion
try:
content = getattr(parent, attr_name)
except AttributeError:
raise AttributeError(
f"{attr_name!r} is configured as a template field "
f"but {parent.task_type} does not have this attribute."
)
else:
if content:
rendered_content = self.render_template(content,
context, jinja_env, seen_oids)
setattr(parent, attr_name, rendered_content)
```
EAFP over LBYL.
--
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]