zhongjiajie commented on code in PR #11606:
URL: https://github.com/apache/dolphinscheduler/pull/11606#discussion_r952411814
##########
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/switch.py:
##########
@@ -107,7 +107,7 @@ def set_define_attr(self) -> None:
num_branch_default += 1
elif isinstance(condition, Branch):
result.append(condition.get_define())
- else:
+ elif num_branch_default >= 1 and isinstance(condition,
Default):
Review Comment:
This code is a little hard to read, maybe we should also change the code
range, raise error ASAP when we meet it. It is my bad about this code
```py
def set_define_attr(self) -> None:
"""Set attribute to function :func:`get_define`.
It is a wrapper for both `And` and `Or` operator.
"""
result = []
num_branch_default = 0
for condition in self.args:
if not isinstance(condition, SwitchBranch):
raise PyDSParamException(
"Task Switch's parameter only support SwitchBranch but
got %s.",
type(condition),
)
# Default number branch checker
if num_branch_default >= 1 and isinstance(condition, Default):
raise PyDSParamException(
"Task Switch's parameter only support SwitchBranch but
got %s.",
type(condition),
)
if isinstance(condition, Default):
self._DEFINE_ATTR.add("next_node")
setattr(self, "next_node", condition.next_node)
num_branch_default += 1
elif isinstance(condition, Branch):
result.append(condition.get_define())
# Handle switch default branch, default value is `""` if not provide.
if num_branch_default == 0:
self._DEFINE_ATTR.add("next_node")
setattr(self, "next_node", "")
setattr(self, "depend_task_list", result)
```
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]