-
Notifications
You must be signed in to change notification settings - Fork 14.6k
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 output
property to MappedOperator
#25604
Conversation
TIL about |
Yeah. Promoting more the TaskFlow and outputs is something we should really do.
|
Yeah slowly trying to change the docs around -- at least to promote TaskFlow API instead of the classic operators. I logged #25319 to update code snippets throughout. |
c5c4031
to
793ace8
Compare
Hmm, the static check failures raise a point for discussion. XComArg has an (unfortunate) API design |
I have the same icky feeling with that current syntax as well. It's also not functionally equivalent to the classic In the meantime, WDYT about allowing |
Side note, the example DAGs were all updated as best as possible to follow the new TaskFlow syntax (see #10285). I have no problem updating these again. |
Doesn’t this conflict with using The general direction feels like a good idea to me though. I also plan to add some mechanism in #25661 to avoid exposing the bracket syntax:
Does this sound like a good plan? |
b14dffc
to
2fc9d41
Compare
output
property to common operator implementationoutput
property to MappedOperator
Sounds like a good one to me. |
f0db611
to
ea3c62f
Compare
f'echo "The xcom pushed manually is {XComArg(bash_push, key="manually_pushed_value")}" && ' | ||
f'echo "The returned_value xcom is {XComArg(bash_push)}" && ' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter one can still use output
although using XComArg
for both is probably more consistent…?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, it might be better to be consistent. There are some other places I need to clean that up to use XComArg()
throughout rather than .output
for now. Is that cool?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although maybe as long as each file is consistent that's fine. .output
is still a valid and useful API. I don't think we want to rip it out of all of the examples.
@@ -99,18 +100,20 @@ | |||
) | |||
# [END howto_operator_ecs_register_task_definition] | |||
|
|||
registered_task_definition = cast(str, register_task.output) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It’s probably a good idea to add a Mapy plugin for this… I’ll look into it after this is merged.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! I was going to ask if there was a better way than doing all of these cast()
calls. Had to be something we could do with mypy specifically.
ea3c62f
to
5219511
Compare
🤞 on CI. I think I finally got everything and new stuff. |
Nice check to make sure providers would still be compatible with Airflow 2.2! Caught some import issues. |
:D :D :D -> sometimes those are REALLY useful (even if annoying). |
Importing `XComArg` directly from the `airflow` namespace wasn't available until 2.3. Providers only have a minimum req of 2.2. The previous import method would have implicitly required a minimum Airflow 2.3 version.
c144471
to
2848743
Compare
# Description ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> The output was implemented in 2.4.0 according to the release notes (see [here](https://airflow.apache.org/docs/apache-airflow/stable/release_notes.html#id13)) Add output property to MappedOperator apache/airflow#25604 <!-- Issues are required for both bug fixes and features. Reference it using one of the following: closes: #ISSUE related: #ISSUE --> closes: #1359 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Catch exception for airflow version < 2.4.0 and use `XComArg(...)` instead. ## Does this introduce a breaking change? No ### Checklist - [x] Created tests which fail without the change (if possible) - [x] Extended the README / documentation, if necessary Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
# Description ## What is the current behavior? <!-- Please describe the current behavior that you are modifying. --> The output was implemented in 2.4.0 according to the release notes (see [here](https://airflow.apache.org/docs/apache-airflow/stable/release_notes.html#id13)) Add output property to MappedOperator apache/airflow#25604 <!-- Issues are required for both bug fixes and features. Reference it using one of the following: closes: #ISSUE related: #ISSUE --> closes: #1359 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Catch exception for airflow version < 2.4.0 and use `XComArg(...)` instead. ## Does this introduce a breaking change? No ### Checklist - [x] Created tests which fail without the change (if possible) - [x] Extended the README / documentation, if necessary Co-authored-by: Kaxil Naik <kaxilnaik@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> (cherry picked from commit 0f5ff62)
Currently the
output
property of operators is only available to unmapped "classic" operators. There can be use cases in whichXComs
from a set of mapped tasks need to be consumed by a downstream task. Of course, accessing these mapped-taskXComs
can be done with the typical Jinja template, but having the convenience of using theoutput
property would be a "quality of life" improvement for DAG authors (especially since task dependencies would then be automatically implemented too).Rather than adding the property toMappedOperator
and have this property definition exist in two locations (along withBaseOperator
), I opted to add this toAbstractOperator
given all tasks have an output even if that output is empty and bothBaseOperator
andMappedOperator
share theAbstractOperator
implementation. If there a higher-level reason to have two instances of the property definition, I'm happy to oblige.This PR adds the
output
property toMappedOperator
and includes a return type annotation forXComArg
. Additionally, until a more appropriate API implementation of accessing a differentXCom
key fromoutput
other than "return_value" is decided, the example DAGs and system tests using this API have been updated to explicitly useXComArg(operator, key=...)
instead.TODO:Add docs demonstrating the use of this property with mapped tasks.May be handled in #25617^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rst
or{issue_number}.significant.rst
, in newsfragments.