You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "Dev-iL (via GitHub)" <gi...@apache.org> on 2025/05/27 11:22:37 UTC
[I] Map length of task_group determined incorrectly [airflow]
Dev-iL opened a new issue, #51109:
URL: https://github.com/apache/airflow/issues/51109
### Apache Airflow version
2.11.0
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
The mapping length in `expandinput` is determined incorrectly to be the **number of returns from a task**, instead of the number of elements in the sequence we map on (which is one of the values returned by the aforementioned task).
Note how `all_lengths` is always `2` regardless of the contents of `value`:


Depending on the relative size of the determined and actual map size, the dag either reports the error below, works correctly, or ends up not processing the later elements.
```none
.../.venv/lib64/python3.11/site-packages/airflow/models/expandinput.py", line 197, in _expand_mapped_field
return value[found_index]
~~~~~^^^^^^^^^^^^^
IndexError: list index out of range
```
### What you think should happen instead?
`all_length` should correctly reflect the number of elements we're mapping on.
### How to reproduce
```python
from __future__ import annotations
import pendulum
from airflow.decorators import task, task_group
from airflow.models.dag import DAG
TYPE_CHECKING: bool = False
if TYPE_CHECKING:
from datetime import datetime
from typing import Any
@task.python(multiple_outputs=True)
def determine_run_params() -> dict[str, Any]:
return {
"targets": [f"target{n}" for n in range(1)], # <<<<<<<<<< Modify for different results
"date": pendulum.now(),
# "str1": "1", # Uncomment these for different results
# "str2": "2",
# "str3": "3",
}
@task.python
def do_something(
target: str,
date: datetime,
) -> str:
return f"All good for {target} on {date}!"
@task_group
def process(
date: datetime,
target: str,
) -> None:
do_something(target, date)
with DAG(
"mcve",
start_date=pendulum.datetime(2020, 1, 1),
) as dag:
run_params = determine_run_params()
process.partial(date=run_params["date"]).expand(target=run_params["targets"])
if __name__ == "__main__":
dag.test()
```
### Operating System
Linux
### Versions of Apache Airflow Providers
_No response_
### Deployment
Other
### Deployment details
_No response_
### Anything else?
When the number of map elements (length of `targets`) is equal to the number of outputs from `determine_run_params`, the code works correctly. Perhaps Airflow's tests related to this functionality are hitting this exact sweet spot.
### Are you willing to submit PR?
- [ ] 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: commits-unsubscribe@airflow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-4989368988
This issue has been closed because it has not received response from the issue author.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "rawwar (via GitHub)" <gi...@apache.org>.
rawwar commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2965285250
> Something like this should be added in the `task_group.py` equivalent.
>
> https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/definitions/mappedoperator.py#L121-L135
@jroachgolf84 , the issue seems to be reported for 2.x. While the PR is raised for 3.x. I'm going through the issue and will also review the PR. But, can you confirm if you verified the bug in 3.x as well? And, will you be raising a separate PR for 2.x branch?(If yes, you need to raise it to v2-11-test)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "jroachgolf84 (via GitHub)" <gi...@apache.org>.
jroachgolf84 commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2931662080
Seems like the issue is parsing the `MappedArgument(_input=DictOfListsExpandInput(value={'target': XComArg(<Task(_PythonDecoratedOperator): determine_run_params>, 'targets')}), _key='target')`. I'm able to successfully get something to work when just passing a `list` to `expand`. However, the behavior seems to differ for `@task_group` vs. `@task`.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "jroachgolf84 (via GitHub)" <gi...@apache.org>.
jroachgolf84 commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2935961054
Something like this should be added in the `task_group.py` equivalent.
https://github.com/apache/airflow/blob/main/task-sdk/src/airflow/sdk/definitions/mappedoperator.py#L121-L135
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "jroachgolf84 (via GitHub)" <gi...@apache.org>.
jroachgolf84 commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2931438182
I'm able to reproduce this exception. The # of dynamically mapped Tasks within a TaskGroup matches the # of elements in the dictionary returned by `determine_run_params`. Just to validate, you're trying to dynamically map TaskGroups (i.e. spin up 10 TaskGroups, each with 1 Task) or dynamically map Tasks (i.e. 1 TaskGroup, each with 10 Tasks)?
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "jroachgolf84 (via GitHub)" <gi...@apache.org>.
jroachgolf84 commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2926336991
Just throwing a comment in here to stay up-to-date, this is one I'd be curious to try and reproduce.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "Dev-iL (via GitHub)" <gi...@apache.org>.
Dev-iL commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2933987431
(@jroachgolf84 I was under the impression that when the needs-triage tag is removed, it is replaced by the determined priority level - low/medium/..., no?)
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "jroachgolf84 (via GitHub)" <gi...@apache.org>.
jroachgolf84 commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2931714170
In the meantime, you'll want to decouple your Task that's returning the `date`, and the one that's returning the `targets`. I think the change to the OSS project is going to be adding validation when parsing the DAG itself.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-4706232657
This issue has been automatically marked as stale because it has been open for 365 days without any activity. There has been several Airflow releases since last activity on this issue. Kindly asking to recheck the report against latest Airflow version and let us know if the issue is reproducible. The issue will be closed in next 30 days if no further activity occurs from the issue author.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "Dev-iL (via GitHub)" <gi...@apache.org>.
Dev-iL commented on issue #51109:
URL: https://github.com/apache/airflow/issues/51109#issuecomment-2931446136
10 groups each with 1 task
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] Map length determined incorrectly when mapping over an output of a multi-output task [airflow]
Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] closed issue #51109: Map length determined incorrectly when mapping over an output of a multi-output task
URL: https://github.com/apache/airflow/issues/51109
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org