-
Notifications
You must be signed in to change notification settings - Fork 13.9k
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
Introduce TaskMixin #10930
Introduce TaskMixin #10930
Conversation
Ok, this one is unexpected:
What should we do: |
I would say B. increase the limit in pylintrc: Lines 551 to 587 in eaa49b2
Currently, |
If vote b too. |
airflow/models/taskmixin.py
Outdated
""" | ||
|
||
@abstractmethod | ||
def set_upstream(self, other): |
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.
Do we want set_upstream
to handle things such as List[XComArg]
or List[TaskGroup]
? If so, maybe we should add the typing to indicate other
can be Union[TaskMixin, List[TaskMixin]]
.
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.
I would love to add some type hints, but I'm not sure if using TaskMixin
is that much informative. But I any other approach will create cyclic imports
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! DRY!
Static check is failing |
Thanks for the PR. This is a great improvement. I think there is room to "DRY" this further. For example, we have a lot of branching logic like this in these methods: In
When we add
I think What do you think? |
I must admit that I didn't get the |
2291ac2
to
792e1cf
Compare
I see. For singular operators such as
We only want to set all the "roots" in group1 as downstream of Same idea applies for "leaves" when we do this. Only the "leaves" in group1 needs to be pulled out and set upstream of operator1.
I think what you have at the moment (operator property) is good enough though for this PR's purpose. The "roots" vs "leaves" problem is very specific to TaskGroup. I'm fine with having such logic live within TaskGroup. |
airflow/models/baseoperator.py
Outdated
@@ -1146,27 +1115,22 @@ def add_only_new(self, item_set: Set[str], item: str) -> None: | |||
else: | |||
item_set.add(item) | |||
|
|||
@property | |||
def operator(self) -> "BaseOperator": |
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.
One request. Is it possible to make this property a List[BaseOperator]
instead? If we want TaskGroup
to implement TaskMixin
, it'll be difficult to decide what operator
should be if it's a singular operator.
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.
I refactored it a bit so now its roots
property - more in line with your initaill proposition
Both BaseOperator and XComArgs implement bit shift operators used to chain tasks in DAGs. By extracting this logic to new mixin we reduce code duplication and make it easier to implement it in future. Closes: apache#10926
ccd82cd
to
db38495
Compare
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. Thank you!
@@ -66,4 +66,4 @@ def print_value(value): | |||
xcom_args_a = print_value("first!") # type: ignore | |||
xcom_args_b = print_value("second!") # type: ignore | |||
|
|||
bash_op1 >> xcom_args_a >> xcom_args_b >> bash_op2 | |||
bash_op1 >> xcom_args_a >> xcom_args_b >> bash_op2 # type: ignore |
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.
oh ! is MyPy complaining here?
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.
I don't get it and I would prefer to solve it in other PR as I believe this will require either mypy plugin or some type changes in @task
decorator. The original error:
airflow/example_dags/example_xcomargs.py:66: error: Value of type variable "T"
of "print_value" cannot be "str"
xcom_args_a = print_value("first!")
^
airflow/example_dags/example_xcomargs.py:67: error: Value of type variable "T"
of "print_value" cannot be "str"
xcom_args_b = print_value("second!")
^
airflow/example_dags/example_xcomargs.py:69: error: Unsupported left operand
type for >> ("BashOperator")
bash_op1 >> xcom_args_a >> xcom_args_b >> bash_op2
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.
ok, fixed? Use @task()
instead of @task
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.
hmm interesting, any idea here @casassg -- "@ task" should work.
This can be addressed in a separate PR though
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.
Both @task
and @task()
works, however the type annotation of this decorator seems to be confusing mypy (althought it looks valid to me)
The single failing build seems to be a flaky something - @kaxil are we good with merging this PR? |
Yup 🚀 |
…ubDagOperator apache#10153 - Introduce TaskMixin (apache#10930) - Test updates
Both BaseOperator and XComArgs implement bit shift operators used to chain tasks in DAGs. By extracting this logic to new mixin we reduce code duplication and make it easier to implement it in the future. This change introduces also root property that allows us to reduce number of type checking. (cherry picked from 0779688)
Both BaseOperator and XComArgs implement bit shift operators used to chain tasks in DAGs. By extracting this logic to new mixin we reduce code duplication and make it easier to implement it in the future. This change introduces also root property that allows us to reduce number of type checking. (cherry picked from 0779688)
Both BaseOperator and XComArgs implement bit shift operators
used to chain tasks in DAGs. By extracting this logic to new
mixin we reduce code duplication and make it easier to implement
it in the future.
Closes: #10926
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code change, 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 UPDATING.md.