You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by zh...@apache.org on 2022/09/17 14:13:40 UTC

[dolphinscheduler] 17/20: [bug][python] Fix task switch error when default branch not defined last (#11606)

This is an automated email from the ASF dual-hosted git repository.

zhongjiajie pushed a commit to branch 3.0.1-prepare
in repository https://gitbox.apache.org/repos/asf/dolphinscheduler.git

commit 1f88c5a637655fefca11cbc4053d1e59e8803c92
Author: JieguangZhou <ji...@163.com>
AuthorDate: Sat Aug 27 18:48:09 2022 +0800

    [bug][python] Fix task switch error when default branch not defined last (#11606)
    
    Co-authored-by: Jiajie Zhong <zh...@gmail.com>
    (cherry picked from commit 635fde19817800221903034c58c858df86e54714)
---
 .../src/pydolphinscheduler/tasks/switch.py         | 25 +++++++++++-----------
 1 file changed, 12 insertions(+), 13 deletions(-)

diff --git a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/switch.py b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/switch.py
index 0c9a2b82b3..05ac9c1329 100644
--- a/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/switch.py
+++ b/dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/switch.py
@@ -99,23 +99,22 @@ class SwitchCondition(Base):
         result = []
         num_branch_default = 0
         for condition in self.args:
-            if isinstance(condition, SwitchBranch):
-                if num_branch_default < 1:
-                    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())
-                else:
-                    raise PyDSParamException(
-                        "Task Switch's parameter only support exactly one default branch."
-                    )
-            else:
+            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 exactly one default branch."
+                )
+            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")