apache / apache/airflow

'airflow tasks tests' for mapped tasks with dependencies

Open
#56,953 5 comments 0 reactions 0 assignees View on GitHub
area:core area:dynamic-task-mapping kind:bug needs-triage
Dominant language
Python
Stars
46.9k
Forks
17.8k
Avg merge
2d 10h
Merged PRs (30d)
483

Description

### Apache Airflow version

Other Airflow 2/3 version (please specify below)

### If "Other Airflow 2/3 version" selected, which one?

3.0.6

### What happened?

I have a simple dag where one map task depends on a single task:

when running `airflow task tests`:
```bash
airflow tasks test problem_dag multiply_by_two --map-index 0 -t '{"number":2}'
```
I get an error saying that the xcoms for `get_numbers` is not found so its defaulting to None, even thought I am testing `multiply_by_two` and provide params for it.
```bash
2025-10-21 13:51:54 [error ] XCom not found [airflow.sdk.api.client] dag_id=problem_dag detail={'detail': {'reason': 'not_found', 'message': "XCom with key='return_value' map_index=-1 not found for task 'get_numbers' in DAG run '__airflow_temporary_run_2025-10-21T13:51:52.789707+00:00__' of 'problem_dag'"}} key=return_value map_index=None run_id=__airflow_temporary_run_2025-10-21T13:51:52.789707+00:00__ status_code=404 task_id=get_numbers
2025-10-21 13:51:54 [warning ] No XCom value found; defaulting to None. [task] dag_id=problem_dag key=return_value map_index=None run_id=__airflow_temporary_run_2025-10-21T13:51:52.789707+00:00__ task_id=get_numbers
```
which than fails

```bash
│ /home/airflow/.local/lib/python3.11/site-packages/airflow/sdk/definitions/xcom_arg.py:596 in _ │
│ │
│ 593 │ if xcom_arg.operator.is_mapped: │
│ 594 │ │ # TODO: How to tell if all the upstream TIs finished? │
│ 595 │ │ pass │
│ ❱ 596 │ return (upstream_map_indexes.get(task_id) or 1) * len(resolved_val)
```
with
```
TypeError: object of type 'NoneType' has no len()
```

The full logs can be found here:
[log.txt](https://github.com/user-attachments/files/23022615/log.txt)

### What you think should happen instead?

When running

```bash
airflow tasks test problem_dag multiply_by_two --map-index 0 -t '{"number":2}'
```
Since all the parameters required , it should either:
- not try to fetch the xcoms from `get_numbers()`
- run `get_numbers()` before it fetches its `xcoms`

### How to reproduce

Run

```bash
airflow tasks test problem_dag multiply_by_two --map-index 0 -t '{"number":2}'
```

for dag
```python
from airflow.decorators import dag, task

@dag
def problem_dag():
@task
def get_numbers(**context):
return [1,2]

@task
def multiply_by_two(number, **context):
return number * 2

numbers = get_numbers()
multiplied_numbers = multiply_by_two.expand(number=numbers)

problem_dag()
```

### Operating System

Debian GNU/Linux 12 (bookworm)

### Versions of Apache Airflow Providers

_No response_

### Deployment

Docker-Compose

### Deployment details

_No response_

### Anything else?

_No response_

### 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)

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the mapped-task dependency case with the `airflow tasks test` command and the `problem_dag` example. Then inspect `airflow/sdk/definitions/xcom_arg.py` around line 596 and compare its XCom lookup with the full `log.txt`. Done means the command handles the provided mapped-task parameters without the missing-XCom warning or `NoneType` error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-engineering, testing
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.