barrywhart opened a new issue, #25344:
URL: https://github.com/apache/airflow/issues/25344
### Description
When an operator uses Jinja templating, debugging issues is difficult
because the Airflow task log only displays a stack trace.
### Use case/motivation
When there's a templating issue, I'd like to have some specific, actionable
info to help understand the problem. At minimum:
* Which operator or task had the issue?
* Which field had the issue?
* What was the Jinja template?
Possibly also the Jinja context, although that can be very verbose.
I have prototyped this in my local Airflow dev environment, and I propose
something like the following. (Note the logging commands, which are not present
in the Airflow repo.)
Please let me know if this sounds reasonable, and I will be happy to create
a PR.
def _do_render_template_fields(
self,
parent,
template_fields,
context,
jinja_env,
seen_oids,
) -> None:
"""Copied from Airflow 2.2.5 with added logging."""
logger.info(f"BaseOperator._do_render_template_fields(): Task
{self.task_id}")
for attr_name in template_fields:
content = getattr(parent, attr_name)
if content:
logger.info(f"Rendering template for '{attr_name}' field:
{content!r}")
rendered_content = self.render_template(content, context,
jinja_env, seen_oids)
+ setattr(parent, attr_name, rendered_content)
### Related issues
_No response_
### Are you willing to submit a PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of
Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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]