-
Notifications
You must be signed in to change notification settings - Fork 13.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Airflow logging for operator Jinja template processing #25452
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
|
||
import datetime | ||
import inspect | ||
import logging | ||
from typing import ( | ||
TYPE_CHECKING, | ||
Any, | ||
|
@@ -77,6 +78,9 @@ | |
) | ||
|
||
|
||
logger = logging.getLogger("airflow.models.abstractoperator.AbstractOperator") | ||
|
||
|
||
class AbstractOperator(LoggingMixin, DAGNode): | ||
"""Common implementation for operators, including unmapped and mapped. | ||
|
||
|
@@ -345,13 +349,22 @@ def _do_render_template_fields( | |
) | ||
if not value: | ||
continue | ||
rendered_content = self.render_template( | ||
value, | ||
context, | ||
jinja_env, | ||
seen_oids, | ||
) | ||
setattr(parent, attr_name, rendered_content) | ||
try: | ||
rendered_content = self.render_template( | ||
value, | ||
context, | ||
jinja_env, | ||
seen_oids, | ||
) | ||
except Exception: | ||
logger.exception( | ||
f"Exception rendering Jinja template for in " | ||
f"task '{self.task_id}', field " | ||
f"'{attr_name}'. Template: {value!r}" | ||
) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done! |
||
raise | ||
else: | ||
setattr(parent, attr_name, rendered_content) | ||
|
||
def render_template( | ||
self, | ||
|
@@ -391,8 +404,8 @@ def render_template( | |
template = jinja_env.from_string(value) | ||
dag = self.get_dag() | ||
if dag and dag.render_template_as_native_obj: | ||
return render_template_as_native(template, context) | ||
return render_template_to_string(template, context) | ||
return render_template_as_native(template, context) # type: ignore[arg-type] | ||
return render_template_to_string(template, context) # type: ignore[arg-type] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Work around There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What are the errors? We do not want to introduce necessary ignores into the code base; if the errors are indeed unrelated, they need to be fixed first. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are the errors. When you say:
Are you requesting that I fix them, or someone else will fix them?
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I removed the For what it's worth, these are the versions of mypy and related packages in my Breeze Docker environment (newly set up yesterday):
|
||
|
||
if isinstance(value, (DagParam, XComArg)): | ||
return value.resolve(context) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added logger instance, following the same pattern as
baseoperator.py
.