jedcunningham commented on code in PR #30943:
URL: https://github.com/apache/airflow/pull/30943#discussion_r1185147061
##########
airflow/models/abstractoperator.py:
##########
@@ -564,8 +564,23 @@ def _do_render_template_fields(
f"{attr_name!r} is configured as a template field "
f"but {parent.task_type} does not have this attribute."
)
- if not value:
- continue
+
+ try:
+ if not value:
+ continue
+ except Exception:
+ # This may happen if the templated field points to a class
which does not support `__bool__`,
+ # such as Pandas DataFrames:
+ #
https://github.com/pandas-dev/pandas/blob/2.0.x/pandas/core/generic.py#L1465
Review Comment:
Let's use a permanent url so this doesn't go stale.
```suggestion
#
https://github.com/pandas-dev/pandas/blob/9135c3aaf12d26f857fcc787a5b64d521c51e379/pandas/core/generic.py#L1465
```
##########
tests/models/test_mappedoperator.py:
##########
@@ -57,6 +59,36 @@ def test_task_mapping_with_dag():
assert mapped.downstream_list == [finish]
+def test_task_mapping_with_dag_and_list_of_pandas_dataframe(caplog):
+ caplog.set_level(logging.INFO)
+
+ class UnrenderableClass:
+ def __bool__(self):
+ raise ValueError("Similar to Pandas DataFrames, this class raises
an exception.")
+
+ class CustomOperator(BaseOperator):
+ template_fields = ("arg",)
+
+ def __init__(self, arg, **kwargs):
+ super().__init__(**kwargs)
+ self.arg = arg
+
+ def execute(self, context: Context):
+ pass
+
+ with DAG("test-dag", start_date=DEFAULT_DATE) as dag:
+ task1 = CustomOperator(task_id="op1", arg=None)
+ unrenderable_values = [UnrenderableClass(), UnrenderableClass()]
+ mapped =
CustomOperator.partial(task_id="task_2").expand(arg=unrenderable_values)
+ task1 >> mapped
+ dag.test()
+ assert caplog.text.count("task_2 ran successfully") == 2
+ assert (
+ "Unable to check if the value of type 'UnrenderableClass' is False for
task 'task_2', field 'arg'"
+ in caplog.text
+ )
+
Review Comment:
Should we test that we `pass`ed instead of `continue`d that field?
--
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]