nickmyatt commented on PR #41513:
URL: https://github.com/apache/airflow/pull/41513#issuecomment-2296180739
Hi @jscheffl, sorry I dashed this fix off in a bit of a rush... Consider
this DAG:
```python
@task
def log_array_param(array: Iterable[str]):
for elem in array:
print(elem)
@dag(schedule="* * * * * ",
start_date=datetime.datetime.fromisoformat("2024-01-01"))
def test_dag(
example_array_param=Param(["foo", "bar"], description="An example of an
array parameter"),
):
log_array_param(example_array_param)
test_dag()
```
If I run this from Airflow UI, I see something like this:

and clicking "Trigger" works as expected (note that `foo` and `bar` get
logged on separate lines, so at runtime the task is getting passed `["foo",
"bar"]`)

However if the DAG gets run on a schedule, the task fails with the following
exception:
```
Traceback (most recent call last):
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/dag.py",
line 3053, in test
_run_task(
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/dag.py",
line 4358, in _run_task
ti._run_raw_task(session=session, raise_on_defer=inline_trigger,
mark_success=mark_success)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/utils/session.py",
line 94, in wrapper
return func(*args, **kwargs)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/taskinstance.py",
line 2995, in _run_raw_task
return _run_raw_task(
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/taskinstance.py",
line 273, in _run_raw_task
TaskInstance._execute_task_with_callbacks(
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/taskinstance.py",
line 3149, in _execute_task_with_callbacks
result = self._execute_task(context, task_orig)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/taskinstance.py",
line 3173, in _execute_task
return _execute_task(self, context, task_orig)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/taskinstance.py",
line 767, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/taskinstance.py",
line 733, in _execute_callable
return ExecutionCallableRunner(
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/utils/operator_helpers.py",
line 252, in run
return self.func(*args, **kwargs)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/baseoperator.py",
line 406, in wrapper
return func(self, *args, **kwargs)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/decorators/base.py",
line 266, in execute
return_value = super().execute(context)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/models/baseoperator.py",
line 406, in wrapper
return func(self, *args, **kwargs)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/operators/python.py",
line 238, in execute
return_value = self.execute_callable()
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/operators/python.py",
line 256, in execute_callable
return runner.run(*self.op_args, **self.op_kwargs)
File
"/home/nickmyatt/.pyenv/versions/3.10.4/lib/python3.10/site-packages/airflow/utils/operator_helpers.py",
line 252, in run
return self.func(*args, **kwargs)
File "/home/nickmyatt/airflow/dags/test_dag.py", line 24, in
log_array_param
for elem in array:
TypeError: 'Param' object is not iterable
```
which is because, at runtime, the task is getting passed `Param(["foo",
"bar"], ....)` rather than `["foo", "bar"]`.
This patch _unwraps_ that `Param`, so that the tasks always sees `["foo",
"bar"]`, regardless of whether manually triggered or run on schedule.
--
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]