You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2020/12/01 19:30:53 UTC

[GitHub] [airflow] kaxil opened a new pull request #12745: Optimize subclasses of DummyOperator for Scheduling

kaxil opened a new pull request #12745:
URL: https://github.com/apache/airflow/pull/12745


   Custom operators inheriting from DummyOperator will now instead
    of going to a scheduled state will go set straight to success
    if they don't have callbacks set.
   
    closes https://github.com/apache/airflow/issues/11393
   
   <!--
   Thank you for contributing! Please make sure that your code changes
   are covered with tests. And in case of new features or big changes
   remember to adjust the documentation.
   
   Feel free to ping committers for the review!
   
   In case of existing issue, reference it using one of the following:
   
   closes: #ISSUE
   related: #ISSUE
   
   How to write a good git commit message:
   http://chris.beams.io/posts/git-commit/
   -->
   
   ---
   **^ Add meaningful description above**
   
   Read the **[Pull Request Guidelines](https://github.com/apache/airflow/blob/master/CONTRIBUTING.rst#pull-request-guidelines)** for more information.
   In case of fundamental code change, Airflow Improvement Proposal ([AIP](https://cwiki.apache.org/confluence/display/AIRFLOW/Airflow+Improvements+Proposals)) is needed.
   In case of a new dependency, check compliance with the [ASF 3rd Party License Policy](https://www.apache.org/legal/resolved.html#category-x).
   In case of backwards incompatible changes please leave a note in [UPDATING.md](https://github.com/apache/airflow/blob/master/UPDATING.md).
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533692462



##########
File path: airflow/models/dagrun.py
##########
@@ -724,7 +724,7 @@ def schedule_tis(self, schedulable_tis: Iterable[TI], session: Session = None) -
             ti
             for ti in schedulable_tis
             if (
-                ti.task.task_type == "DummyOperator"
+                (ti.task.task_type == "DummyOperator" or getattr(ti.task, "_is_dummy", False))

Review comment:
       This is just for backwards-compatibility so the current Serialized DAGs which don't have `_is_dummy` field still continue to work

##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -432,6 +437,9 @@ def deserialize_operator(cls, encoded_op: Dict[str, Any]) -> BaseOperator:
             if not hasattr(op, field):
                 setattr(op, field, None)
 
+        # Used to determine if an Operator is inherited from DummyOperator
+        setattr(op, "_is_dummy", bool(encoded_op.get("_is_dummy")))

Review comment:
       fixed in https://github.com/apache/airflow/pull/12745/commits/67b5daf93d7a791670966cea806429155a303041




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] mik-laj commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
mik-laj commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533687889



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       We have a serialized DAG here, so the isinstance function is not behaving properly. From the isinstance point of view, we have BaseOperator here.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil merged pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil merged pull request #12745:
URL: https://github.com/apache/airflow/pull/12745


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533705611



##########
File path: airflow/models/baseoperator.py
##########
@@ -1371,6 +1371,11 @@ def is_smart_sensor_compatible(self):
         """Return if this operator can use smart service. Default False."""
         return False
 
+    @property
+    def inherits_from_dummy_operator(self):
+        """Used to determine if an Operator is inherited from DummyOperator"""

Review comment:
       ```suggestion
           """Used to determine if an Operator is inherited from DummyOperator"""
           # This looks like `isinstance(self, DummyOperator) would work, but this also needs to cope when `self` is a Serialized instance of a DummyOperator or one of its sub-classes (which don't inherit from anything but BaseOperator).
   ```
   
   But with line wrapping




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533692904



##########
File path: airflow/models/dagrun.py
##########
@@ -724,7 +724,7 @@ def schedule_tis(self, schedulable_tis: Iterable[TI], session: Session = None) -
             ti
             for ti in schedulable_tis
             if (
-                ti.task.task_type == "DummyOperator"
+                (ti.task.task_type == "DummyOperator" or getattr(ti.task, "_is_dummy", False))

Review comment:
       Maybe not needed after 67b5daf 🤔 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533668834



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       I did not add check to see if the execute method is empty or not like we discussed @ashb. My thinking for that was as it is a DummyOperator where we list it should do nothing, let's just keep it simple.
   
   WDYT?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533673864



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       Should we just simply do `isinstance(op, DummyOperator)`, why check the `task_type`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533691190



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -432,6 +437,9 @@ def deserialize_operator(cls, encoded_op: Dict[str, Any]) -> BaseOperator:
             if not hasattr(op, field):
                 setattr(op, field, None)
 
+        # Used to determine if an Operator is inherited from DummyOperator
+        setattr(op, "_is_dummy", bool(encoded_op.get("_is_dummy")))

Review comment:
       ```suggestion
           setattr(op, "_is_dummy", bool(encoded_op.get("_is_dummy", False)))
   ```
   
   To load existing s10n blobs.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533694952



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       Using the approach I suggested (if it works), you can just get rid of this method :)




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533673864



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       Should we just simply do `isinstance(op, DummyOperator)`, why check the `task_type`? Anyway, we can just do:
   ```
   return op.task_type == "DummyOperator" or isinstance(op, DummyOperator)
   ```




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533690595



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       One for real dag, one for Serialzed dag I think




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533694350



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       Yeah if for whatever reason if there is a SerializedOperator, than we need to check `op.task_type`.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533695666



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       Let me give that a try




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533703585



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       Works like a charm, thanks.
   
   Updated in https://github.com/apache/airflow/pull/12745/commits/0b47a1b9d251a0ac84a366892701585a831fc892




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] turbaszek commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
turbaszek commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533672482



##########
File path: airflow/models/dagrun.py
##########
@@ -724,7 +724,7 @@ def schedule_tis(self, schedulable_tis: Iterable[TI], session: Session = None) -
             ti
             for ti in schedulable_tis
             if (
-                ti.task.task_type == "DummyOperator"
+                (ti.task.task_type == "DummyOperator" or getattr(ti.task, "_is_dummy", False))

Review comment:
       ```suggestion
                   (getattr(ti.task, "_is_dummy", False)
   ```
   Should this be enough? I think `DummyOperator` will also fall in this category




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533707158



##########
File path: airflow/models/baseoperator.py
##########
@@ -1371,6 +1371,11 @@ def is_smart_sensor_compatible(self):
         """Return if this operator can use smart service. Default False."""
         return False
 
+    @property
+    def inherits_from_dummy_operator(self):
+        """Used to determine if an Operator is inherited from DummyOperator"""

Review comment:
       Pushed: https://github.com/apache/airflow/pull/12745/commits/b150a6a60be8a2cffd22069e797a48e30d41967f




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] github-actions[bot] commented on pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
github-actions[bot] commented on pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#issuecomment-736871498


   The PR most likely needs to run full matrix of tests because it modifies parts of the core of Airflow. However, committers might decide to merge it quickly and take the risk. If they don't merge it quickly - please rebase it to the latest master at your convenience, or amend the last commit of the PR, and push it with --force-with-lease.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533692459



##########
File path: airflow/serialization/serialized_objects.py
##########
@@ -532,6 +540,13 @@ def _serialize_operator_extra_links(cls, operator_extra_links: Iterable[BaseOper
 
         return serialize_operator_extra_links
 
+    @classmethod
+    def _is_inherited_from_dummy_operator(cls, op: BaseOperator) -> bool:
+        """Used to determine if an Operator is inherited from DummyOperator"""
+        if op.task_type == "DummyOperator" or isinstance(op, DummyOperator):

Review comment:
       How about instead of this approach,
   
   Add a method/propery on to BaseOperator:
   
   ```
   class BaseOperator:
       @property
       def inherits_from_dummy_operator(self):
           getattr(self, '_is_dummy', False)
   ```
   
   And then
   
   ```
   class DummyOperator(BaseOperator):
       inherits_from_dummy_operator = True
   ```
   
   That way this method isn't needed, and at runtime in both cases (real or serialized) we can just look at `op.inherits_from_dummy_operator




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] kaxil commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
kaxil commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533672397



##########
File path: tests/dags/test_only_dummy_tasks.py
##########
@@ -29,14 +29,24 @@
 
 dag = DAG(dag_id="test_only_dummy_tasks", default_args=default_args, schedule_interval='@once')
 
+

Review comment:
       This DAG is used by `test_should_mark_dummy_task_as_success` test in `tests/jobs/test_scheduler_job.py`




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [airflow] ashb commented on a change in pull request #12745: Optimize subclasses of DummyOperator for Scheduling

Posted by GitBox <gi...@apache.org>.
ashb commented on a change in pull request #12745:
URL: https://github.com/apache/airflow/pull/12745#discussion_r533697547



##########
File path: airflow/models/dagrun.py
##########
@@ -724,7 +724,7 @@ def schedule_tis(self, schedulable_tis: Iterable[TI], session: Session = None) -
             ti
             for ti in schedulable_tis
             if (
-                ti.task.task_type == "DummyOperator"
+                (ti.task.task_type == "DummyOperator" or getattr(ti.task, "_is_dummy", False))

Review comment:
       I think right now this could be used in Scheduler (on serialized dags) and Backfill (on real DAGs) so that commit alone won't help.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org