Skip to content

TaskFlow unexpectedly unwinds 'dict' #27819

Description

@bolkedebruin

Apache Airflow version

main (development)

What happened

if using the TaskFlow API and one does the following

@task()
def MyFunc(myarg: int) -> dict:
  return dict({x: "y", z: "x"})

Airflow automatically unwinds dict automatically into separate variables x and z and if you do not want that kind of bahavior you will need to set multiple_outputs=False. While this is in the documentation, it is rather non intuitive requiring someone to be aware of the documentation that the default of multiple_outputs changes depending the return type of your function. Moreover, it is unexpected behavior for people coming from plain python (e.g. someone converting their functions to Airflow tasks) and wanting to do:

@task()
def f1(myarg: int) -> dict:
  return dict({x: myarg, z: "x"})

@task
def f2(in: dict):
  print(in)

a = f1(10)
f2(a)

Which would suddenly have issues in unittesting.

cc @josh-fell @BasPH @uranusjr

What you think should happen instead

Airflow should only unwind dicts if explicitly asked to do so.

How to reproduce

No response

Operating System

Not relevant

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    AIP-31Task Flow API for nicer DAG definitionarea:corekind:featureFeature Requests

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions