Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add multiple_outputs option to PythonOperator #37284

Closed
2 tasks done
jannisko opened this issue Feb 9, 2024 · 2 comments · Fixed by #37297
Closed
2 tasks done

Add multiple_outputs option to PythonOperator #37284

jannisko opened this issue Feb 9, 2024 · 2 comments · Fixed by #37297
Labels
area:core area:core-operators Operators, Sensors and hooks within Core Airflow kind:feature Feature Requests

Comments

@jannisko
Copy link
Contributor

jannisko commented Feb 9, 2024

Description

Add a new optional field return_multiple to PythonOperator, which automatically splits returned dicts into separate XComs.

Use case/motivation

Currently, the task-flow decorator @task accepts a boolean argument multiple_outputs, which automatically splits any returned dictionary of values into separate xcom values. Using this feature, the following code can be compacted from

@task
def split_csv(task_instance: TaskInstance, csv_path: ObjectStoragePath) -> None
    ...
    task_instance.xcom_push("rows_csv", rows_csv)
    task_instance.xcom_push("summary_csv", summary_csv)

to

@task(mulitple_outputs=True)
def split_csv(csv_path: ObjectStoragePath) -> dict[str, ObjectStoragePath]
    ...
    return {"rows_csv": rows_csv, "summary_csv": summary_csv}

This abstracts away the airflow-ism of task instances and still enables using each part of the returned value separately via e.g. split_csv.output["rows_csv"].

This feature is not available for any other operator, though I feel like it would be very useful. I'm open to implementing this by applying the existing code from airflow.decorators.base.DecoratedOperator to PythonOperator, since BaseOperator doesn't implement any handling of returned values.

Please let me know what you think about this change. 🙂

Related issues

No response

Are you willing to submit a PR?

  • Yes I am willing to submit a PR!

Code of Conduct

@jannisko jannisko added kind:feature Feature Requests needs-triage label for new issues that we didn't triage yet labels Feb 9, 2024
Copy link

boring-cyborg bot commented Feb 9, 2024

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.

@hussein-awala hussein-awala added area:core-operators Operators, Sensors and hooks within Core Airflow and removed needs-triage label for new issues that we didn't triage yet labels Feb 9, 2024
@hussein-awala
Copy link
Member

I think it's a good idea, I will take a look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area:core area:core-operators Operators, Sensors and hooks within Core Airflow kind:feature Feature Requests
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants