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 2021/05/13 10:51:34 UTC

[GitHub] [airflow] uranusjr opened a new pull request #15821: Refactor out callback isinstance() checks

uranusjr opened a new pull request #15821:
URL: https://github.com/apache/airflow/pull/15821


   The `isinstance()` checks to execute callbacks cause eyesore, so I refactored them into polymorphism calls instead. Putting the functions in `airflow.utils` raises some circular import issues (not surprising), but I think I’ve done just enough to resolve them. Hopefully we can restructure the imports better into future to avoid these function-local imports.
   
   ---
   **^ 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] github-actions[bot] commented on pull request #15821: Refactor out callback isinstance() checks

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


   [The Workflow run](https://github.com/apache/airflow/actions/runs/838793129) is cancelling this PR. It has some failed jobs matching ^Pylint$,^Static checks,^Build docs$,^Spell check docs$,^Provider packages,^Checks: Helm tests$,^Test OpenAPI*.


-- 
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] uranusjr commented on a change in pull request #15821: Refactor out callback isinstance() checks

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



##########
File path: airflow/utils/callback_requests.py
##########
@@ -41,8 +54,12 @@ def __eq__(self, other):
     def __repr__(self):
         return str(self.__dict__)
 
+    def execute(self, dagbag: "DagBag", *, session: Session) -> None:
+        """Execute the callback."""
+        raise NotImplementedError("implement in subclass")
+
 
-class TaskCallbackRequest(CallbackRequest):
+class TaskCallbackRequest(CallbackRequest, LoggingMixin):

Review comment:
       Alternatively I can pass in the logger instance as an argument of `execute()` instead? I don’t really like making CallbackRequest instances subclass from `LoggingMixin` tbh, but passing a logger around also feels a bit weird.




-- 
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 #15821: Refactor out callback isinstance() checks

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






-- 
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 #15821: Refactor out callback isinstance() checks

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






-- 
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 #15821: Refactor out callback isinstance() checks

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



##########
File path: airflow/utils/callback_requests.py
##########
@@ -56,14 +73,36 @@ class TaskCallbackRequest(CallbackRequest):
     def __init__(
         self,
         full_filepath: str,
-        simple_task_instance: SimpleTaskInstance,
+        simple_task_instance: "SimpleTaskInstance",
         is_failure_callback: Optional[bool] = True,
         msg: Optional[str] = None,
     ):
         super().__init__(full_filepath=full_filepath, msg=msg)
         self.simple_task_instance = simple_task_instance
         self.is_failure_callback = is_failure_callback
 
+    def execute(self, dagbag: "DagBag", *, session: Session) -> None:  # pylint: disable=unused-argument

Review comment:
       Yeah previously this was a conscious effort to only pass namedTuple ( which we  converted to simple objects/clases) to send to multiprocessingng PIPES.
   
   




-- 
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 #15821: Refactor out callback isinstance() checks

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


   This pull request has been automatically marked as stale because it has not had recent activity. It will be closed in 5 days if no further activity occurs. Thank you for your contributions.


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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



[GitHub] [airflow] kaxil commented on a change in pull request #15821: Refactor out callback isinstance() checks

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



##########
File path: airflow/utils/callback_requests.py
##########
@@ -56,14 +73,36 @@ class TaskCallbackRequest(CallbackRequest):
     def __init__(
         self,
         full_filepath: str,
-        simple_task_instance: SimpleTaskInstance,
+        simple_task_instance: "SimpleTaskInstance",
         is_failure_callback: Optional[bool] = True,
         msg: Optional[str] = None,
     ):
         super().__init__(full_filepath=full_filepath, msg=msg)
         self.simple_task_instance = simple_task_instance
         self.is_failure_callback = is_failure_callback
 
+    def execute(self, dagbag: "DagBag", *, session: Session) -> None:  # pylint: disable=unused-argument

Review comment:
       However, if this is working fine -- no issue with that :) 




-- 
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 #15821: Refactor out callback isinstance() checks

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



##########
File path: airflow/utils/callback_requests.py
##########
@@ -41,8 +54,12 @@ def __eq__(self, other):
     def __repr__(self):
         return str(self.__dict__)
 
+    def execute(self, dagbag: "DagBag", *, session: Session) -> None:
+        """Execute the callback."""
+        raise NotImplementedError("implement in subclass")
+
 
-class TaskCallbackRequest(CallbackRequest):
+class TaskCallbackRequest(CallbackRequest, LoggingMixin):

Review comment:
       This is _probably_ safe, but these objects are passed over a multiprocessing Pipe, so are subject to pickling, so we should create a `__getstate__`(?) method to ensure that `self.log` is never attempted to be pickled. 




-- 
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] uranusjr closed pull request #15821: Refactor out callback isinstance() checks

Posted by GitBox <gi...@apache.org>.
uranusjr closed pull request #15821:
URL: https://github.com/apache/airflow/pull/15821


   


-- 
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.

To unsubscribe, e-mail: commits-unsubscribe@airflow.apache.org

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