This is an automated email from the ASF dual-hosted git repository.
pierrejeambrun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/airflow.git
The following commit(s) were added to refs/heads/main by this push:
new a5dd08a930 Handle returned None when multiple_outputs is True (#32625)
a5dd08a930 is described below
commit a5dd08a9302acca77c39e9552cde8ef501fd788f
Author: Hussein Awala <[email protected]>
AuthorDate: Sun Jul 16 16:31:32 2023 +0200
Handle returned None when multiple_outputs is True (#32625)
---
airflow/decorators/base.py | 2 +-
tests/decorators/test_python.py | 13 +++++++++++++
2 files changed, 14 insertions(+), 1 deletion(-)
diff --git a/airflow/decorators/base.py b/airflow/decorators/base.py
index 7e3c8ba2c9..b2059eb6b4 100644
--- a/airflow/decorators/base.py
+++ b/airflow/decorators/base.py
@@ -237,7 +237,7 @@ class DecoratedOperator(BaseOperator):
for item in return_value:
if isinstance(item, Dataset):
self.outlets.append(item)
- if not self.multiple_outputs:
+ if not self.multiple_outputs or return_value is None:
return return_value
if isinstance(return_value, dict):
for key in return_value.keys():
diff --git a/tests/decorators/test_python.py b/tests/decorators/test_python.py
index 3cf49c98b0..cd69759995 100644
--- a/tests/decorators/test_python.py
+++ b/tests/decorators/test_python.py
@@ -267,6 +267,19 @@ class TestAirflowTaskDecorator(BasePythonTest):
ti = dr.get_task_instances()[0]
assert ti.xcom_pull() == {}
+ def test_multiple_outputs_return_none(self):
+ @task_decorator(multiple_outputs=True)
+ def test_func():
+ return
+
+ with self.dag:
+ ret = test_func()
+
+ dr = self.create_dag_run()
+ ret.operator.run(start_date=DEFAULT_DATE, end_date=DEFAULT_DATE)
+ ti = dr.get_task_instances()[0]
+ assert ti.xcom_pull() is None
+
def test_python_callable_arguments_are_templatized(self):
"""Test @task op_args are templatized"""