uranusjr commented on code in PR #55068:
URL: https://github.com/apache/airflow/pull/55068#discussion_r2986545312
##########
task-sdk/src/airflow/sdk/definitions/_internal/templater.py:
##########
@@ -117,6 +117,48 @@ def _should_render_native(self, dag: DAG | None = None) ->
bool:
return dag.render_template_as_native_obj if dag else False
+ def _iter_templated_fields(
+ self,
+ parent: Any,
+ template_fields: Iterable[str],
+ ) -> Iterator[tuple[str, Any]]:
+ """
+ Iterate over template fields yielding ``(attr_name, value)`` pairs for
non-empty fields.
+
+ Fields whose value is falsy are skipped. Objects that do not support
+ ``__bool__`` (e.g. Pandas DataFrames) are still yielded.
+ """
+ for attr_name in template_fields:
+ try:
+ value = getattr(parent, attr_name)
+ except AttributeError:
+ raise AttributeError(
+ f"{attr_name!r} is configured as a template field "
+ f"but {type(parent).__name__} does not have this
attribute."
+ )
+ try:
+ if not value:
+ continue
Review Comment:
I don’t think it’d be a problem to render empty values anyway…? Why do we
need to do this?
--
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]