Skip to content

Filtering items from a mapped task is broken #49737

@GeryDeKocliko

Description

@GeryDeKocliko

Apache Airflow version

3.0.0

If "Other Airflow 2 version" selected, which one?

No response

What happened?

Hi,

As outlined in the documentation, I’m attempting to filter out items in my dynamic task mapping by returning None within the filter task.

See : https://airflow.apache.org/docs/apache-airflow/stable/authoring-and-scheduling/dynamic-task-mapping.html#filtering-items-from-a-mapped-task

However, I’m observing that None values are still being passed to the subsequent expand, which is not the expected behavior.

What you think should happen instead?

The None value must not be passed to the next expand.

How to reproduce

from airflow.decorators import dag, task

@task
def generate_data():
    return [1, None, 3]


@task
def filter_item_from_mapped_task(item):
    if item is None:
        return None
    return item


@task
def print_item(item):
    assert item is not None
    print(item)


@dag(
    dag_id='test_bug_dag',
)
def test_bug_dag():
    data = generate_data()
    filtered_data = filter_item_from_mapped_task.expand(item=data)
    print_item.expand(item=filtered_data)

test_bug_dag()

Operating System

MacOS 14.6 (23G80)

Versions of Apache Airflow Providers

I haven’t added any additional providers

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

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions