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/09/29 19:37:06 UTC

[GitHub] [airflow] edwardwang888 commented on a change in pull request #18471: Improve error message for BranchPythonOperator when no task_id to follow

edwardwang888 commented on a change in pull request #18471:
URL: https://github.com/apache/airflow/pull/18471#discussion_r718826421



##########
File path: airflow/operators/python.py
##########
@@ -178,6 +178,19 @@ class BranchPythonOperator(PythonOperator, SkipMixin):
 
     def execute(self, context: Dict):
         branch = super().execute(context)
+        # TODO: The logic should be moved to SkipMixin to be available to all branch operators.
+        if isinstance(branch, str):
+            branches = {branch}
+        elif isinstance(branch, list):
+            branches = set(branch)
+        else:
+            raise AirflowException("Branch callable must return either a task ID or a list of IDs")
+        valid_task_ids = set(context["dag"].task_ids)
+        invalid_task_ids = branches - valid_task_ids
+        if invalid_task_ids:
+            raise AirflowException(
+                f"Branch callable must valid task_ids. Invalid tasks found: {invalid_task_ids}"

Review comment:
       @eladkal Did you mean something like
   `Branch callable must *return* valid task_ids`?




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