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/24 09:32:05 UTC
[GitHub] [airflow] uranusjr commented on a change in pull request #18471: Improve error message for BranchPythonOperator when no task_id to follow
uranusjr commented on a change in pull request #18471:
URL: https://github.com/apache/airflow/pull/18471#discussion_r715463290
##########
File path: airflow/operators/python.py
##########
@@ -178,6 +178,8 @@ class BranchPythonOperator(PythonOperator, SkipMixin):
def execute(self, context: Dict):
branch = super().execute(context)
+ if branch is None:
+ raise AirflowException("Branch callable must return at least one task_id to follow")
Review comment:
Kind of wondering whether we should check for all non-str values. Or even check the value is a valid task ID? Something likeā¦
```python
if isinstance(branch, str):
branches = [branch]
try:
branches = list(branch) # Check iterability.
except TypeError:
raise AirflowException("Branch callable must return either a task ID or a list of IDs")
valid_task_ids = set(context["context"].task_ids)
if not any(b in valid_task_ids for b in branches):
raise AirflowException("Branch callable must return at least one task ID to follow")
```
--
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