Skip to content

Result of expanded task is None instead of empty list when all mapped tasks return None #48005

Closed as not planned

Description

@cedricdeboom

Apache Airflow version

2.10.5

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

No response

What happened?

Upon expanding a task using a list of variables, the return value of the task should be a list of all the individual return values. When the return value of one mapped task is None, it is automatically filtered out of this list. You might expect then that if all mapped tasks return None, the list is empty. However, that is not the case. Instead of returning an empty list, the return value is None. This causes issues if the output is used to expand upon in downstream tasks.

What you think should happen instead?

The return value of an expanded task should always be a list, even if all the mapped tasks have returned None (in which case the list should be empty, not None).

How to reproduce

Example dag to reproduce.

import logging
from datetime import datetime
from airflow.decorators import dag, task

logger = logging.getLogger(__name__)

@dag(schedule=None, start_date=datetime(2024, 3, 20), catchup=False, dag_id="example_dag")
def example_dag():

    @task
    def generate_data():
        # Generating a list of numbers
        return [1, 3]

    @task
    def filter_data(number):
        # Filtering only even numbers
        return number if number % 2 == 0 else None

    @task
    def display_results(results):
        logger.info(results)

    numbers = generate_data()

    filtered_numbers = filter_data.expand(number=numbers)
    display_results(filtered_numbers)

example_dag()

Operating System

MacOS Sequoia 15.3.2

Versions of Apache Airflow Providers

No response

Deployment

Virtualenv installation

Deployment details

Standalone

Anything else?

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Mar 20, 2025
  2. boring-cyborg commented on Mar 20, 2025

    @boring-cyborg

    Thanks for opening your first issue here! Be sure to follow the issue template! If you are willing to raise PR to address this issue please do so, no need to wait for approval.

  3. sunank200 commented on Mar 24, 2025

    @sunank200
    Collaborator

    With the DAG you provided, I am able to replicate this issue, and it is returning None. Do we want to change this behaviour?

    cc: @pankajastro WDYT?

  4. removed
    needs-triage
    on Mar 24, 2025
  5. cedricdeboom commented on Mar 24, 2025

    @cedricdeboom
    Author

    I think it should be an empty list to maintain consistent behavior. This is important if you want to use this filtered list to expand downstream tasks upon.

    Also: if you'd change return [1, 3] to return [1, 2, 3] in the provided DAG, the result will be [2] (i.e. a single 2 wrapped inside a list) and not just 2. So, always return a list, I'd say :)

  6. isaiahiruoha commented on Aug 8, 2025

    @isaiahiruoha
    Contributor

    Quick note, reproduced this issue on 2.10.5, also seems as though it has been resolved in the main branch. Running the DAG on main will return an empty list "[]" rather then None.

  7. Desdroid commented on Jun 26, 2026

    @Desdroid
    Contributor

    Quick note, reproduced this issue on 2.10.5, also seems as though it has been resolved in the main branch. Running the DAG on main will return an empty list "[]" rather then None.

    This was indeed fixed on main and now has regressed. Would be nice to know what the desired outcome is from maintainers perspective and then add tests for this 😄

  8. shahar1 commented on Jun 27, 2026

    @shahar1
    Contributor

    Closing as resolved - the literal example in this issue works properly as the .expand(...) now covers it.
    However, #69036 is indeed a new issue caused by migration to the task sdk, which has a similar root cause.
    Created a PR to solve it #69075.

  9. Desdroid commented on Jun 29, 2026

    @Desdroid
    Contributor

    Closing as resolved - the literal example in this issue works properly as the .expand(...) now covers it. However, #69036 is indeed a new issue caused by migration to the task sdk, which has a similar root cause. Created a PR to solve it #69075.

    @shahar1 Are you sure that this issue here is resolved? I can reproduce it with an 3.2.2 installation, copy pasting the example dag above.
    display_results prints None instead of an empty list for me.
    Thanks for looking into it and the PR 🫶

  10. shahar1 commented on Jun 29, 2026

    @shahar1
    Contributor

    Closing as resolved - the literal example in this issue works properly as the .expand(...) now covers it. However, #69036 is indeed a new issue caused by migration to the task sdk, which has a similar root cause. Created a PR to solve it #69075.

    @shahar1 Are you sure that this issue here is resolved? I can reproduce it with an 3.2.2 installation, copy pasting the example dag above.
    display_results prints None instead of an empty list for me.
    Thanks for looking into it and the PR 🫶

    Please let me double check on it, reopening.

  11. shahar1 commented on Jun 30, 2026

    @shahar1
    Contributor

    Closing as resolved - the literal example in this issue works properly as the .expand(...) now covers it. However, #69036 is indeed a new issue caused by migration to the task sdk, which has a similar root cause. Created a PR to solve it #69075.

    @shahar1 Are you sure that this issue here is resolved? I can reproduce it with an 3.2.2 installation, copy pasting the example dag above.
    display_results prints None instead of an empty list for me.
    Thanks for looking into it and the PR 🫶

    Please let me double check on it, reopening.

    @Desdroid
    When running on main, I got the following output:

    [2026-06-30T07:40:47.208203Z] INFO - LazyXComSequence(<unevaluated length>)
    [2026-06-30T07:40:47.208477Z] INFO - Done. Returned value was: None
    

    display_results returns None because it just logs (logger.info(results)) and doesn't actually return anything.

    Reclosing :)

  12. cedricdeboom commented on Jun 30, 2026

    @cedricdeboom
    Author

    @shahar1 But the desired behavior (at least in my eyes) is that it returns [] and not None.

  13. shahar1 commented on Jun 30, 2026

    @shahar1
    Contributor

    @shahar1 But the desired behavior (at least in my eyes) is that it returns [] and not None.

    Hey, I was too focused on solving the other bug so I completely missed out the real intent of this issue - my sincere apologies for that.
    As it changes an existing core behavior, it will require a discussion and lazy consensus on Airflow's dev list. If you already did so in the past, could you please bump it? Otherwise, could you please create a thread for that? (With expalanation of the necessity, examples for misusage of current behavior, etc.)

    Thank you! Reopening again.

  14. cedricdeboom commented on Jun 30, 2026

    @cedricdeboom
    Author

    I'm not an active contributor here, but I feel that @Desdroid is well-placed to defend the change :) so I'll leave it up to them!

  15. Desdroid commented on Jul 1, 2026

    @Desdroid
    Contributor

    Closing as resolved - the literal example in this issue works properly as the .expand(...) now covers it. However, #69036 is indeed a new issue caused by migration to the task sdk, which has a similar root cause. Created a PR to solve it #69075.

    @shahar1 Are you sure that this issue here is resolved? I can reproduce it with an 3.2.2 installation, copy pasting the example dag above.
    display_results prints None instead of an empty list for me.
    Thanks for looking into it and the PR 🫶

    Please let me double check on it, reopening.

    @Desdroid When running on main, I got the following output:

    [2026-06-30T07:40:47.208203Z] INFO - LazyXComSequence(<unevaluated length>)
    [2026-06-30T07:40:47.208477Z] INFO - Done. Returned value was: None
    

    display_results returns None because it just logs (logger.info(results)) and doesn't actually return anything.

    Reclosing :)

    Well, I should've double checked before posting. Somehow got confused which log line was which. Indeed LazyXComSequence is received which is the desired behavior from my point of view. I'm sincerely sorry for the confusion.

    @shahar1 But the desired behavior (at least in my eyes) is that it returns [] and not None.

    I am against this. Why should a method that does not have a return statement suddenly return an empty list? This is different from how (normal) python works and I'd consider it unpythonic.

    The original title of this issue is Result of expanded task is None instead of empty list when all mapped tasks return None and also from the previous comments and description i understood that it was about the display_results() receiving None as a result of the expanded tasks while it now receives LazyXComSequence -> empty list, which is correct imo.

    Therefore I'd vote to close this.

  16. shahar1 commented on Jul 1, 2026

    @shahar1
    Contributor

    Closing as resolved - the literal example in this issue works properly as the .expand(...) now covers it. However, #69036 is indeed a new issue caused by migration to the task sdk, which has a similar root cause. Created a PR to solve it #69075.

    @shahar1 Are you sure that this issue here is resolved? I can reproduce it with an 3.2.2 installation, copy pasting the example dag above.
    display_results prints None instead of an empty list for me.
    Thanks for looking into it and the PR 🫶

    Please let me double check on it, reopening.

    @Desdroid When running on main, I got the following output:

    [2026-06-30T07:40:47.208203Z] INFO - LazyXComSequence(<unevaluated length>)
    [2026-06-30T07:40:47.208477Z] INFO - Done. Returned value was: None
    

    display_results returns None because it just logs (logger.info(results)) and doesn't actually return anything.
    Reclosing :)

    Well, I should've double checked before posting. Somehow got confused which log line was which. Indeed LazyXComSequence is received which is the desired behavior from my point of view. I'm sincerely sorry for the confusion.

    @shahar1 But the desired behavior (at least in my eyes) is that it returns [] and not None.

    I am against this. Why should a method that does not have a return statement suddenly return an empty list? This is different from how (normal) python works and I'd consider it unpythonic.

    The original title of this issue is Result of expanded task is None instead of empty list when all mapped tasks return None and also from the previous comments and description i understood that it was about the display_results() receiving None as a result of the expanded tasks while it now receives LazyXComSequence -> empty list, which is correct imo.

    Therefore I'd vote to close this.

    It's alright, no worries :) At least we're all aware of what it is all about now.
    Anyway, considering that you're against it, I don't fully understand that intent, and Cedric, as the issue author, doesn't plan to push it - I don't see this going anywhere.
    However, as I've already swayed between closing and reopening this issue too much for one day, I'll leave it as pending-response until someone else justifies it, or creates the thread on the dev list, or that the issue gets auto-closed - whichever comes first.

  17. github-actions commented on Jul 18, 2026

    @github-actions
    Contributor

    This issue has been automatically marked as stale because it has been open for 14 days with no response from the author. It will be closed in next 7 days if no further activity occurs from the issue author.

  18. added
    stale
    on Jul 18, 2026
  19. github-actions commented on Jul 25, 2026

    @github-actions
    Contributor

    This issue has been closed because it has not received response from the issue author.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area:corearea:dynamic-task-mappingkind:bugpending-responsestale

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions