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

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

commit 0f94849625cc76e5022783f0644aaf107f4e7786
Author: Jay Chung <[email protected]>
AuthorDate: Mon Sep 18 18:44:49 2023 +0800

    fix datasource get attribute error
---
 src/pydolphinscheduler/core/resource.py     |  2 +-
 src/pydolphinscheduler/core/workflow.py     |  4 ++--
 src/pydolphinscheduler/java_gateway.py      |  7 ++++++-
 src/pydolphinscheduler/models/datasource.py | 18 ++++++++++--------
 4 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/src/pydolphinscheduler/core/resource.py 
b/src/pydolphinscheduler/core/resource.py
index 3e04f9b..60c2115 100644
--- a/src/pydolphinscheduler/core/resource.py
+++ b/src/pydolphinscheduler/core/resource.py
@@ -19,10 +19,10 @@
 
 from typing import Optional
 
+from pydolphinscheduler import configuration
 from pydolphinscheduler.exceptions import PyDSParamException
 from pydolphinscheduler.java_gateway import gateway
 from pydolphinscheduler.models import Base
-from pydolphinscheduler import configuration
 
 
 class Resource(Base):
diff --git a/src/pydolphinscheduler/core/workflow.py 
b/src/pydolphinscheduler/core/workflow.py
index e0e00b8..7303a61 100644
--- a/src/pydolphinscheduler/core/workflow.py
+++ b/src/pydolphinscheduler/core/workflow.py
@@ -178,8 +178,8 @@ class Workflow(Base):
 
         # do not thing but for air2phin migrate
         self.schedule = None
-        if 'schedule' in kwargs or 'schedule_interval' in kwargs:
-            self.schedule = kwargs.get('schedule') or 
kwargs.get('schedule_interval')
+        if "schedule" in kwargs or "schedule_interval" in kwargs:
+            self.schedule = kwargs.get("schedule") or 
kwargs.get("schedule_interval")
 
     def __enter__(self) -> "Workflow":
         WorkflowContext.set(self)
diff --git a/src/pydolphinscheduler/java_gateway.py 
b/src/pydolphinscheduler/java_gateway.py
index 736c1d7..3c90776 100644
--- a/src/pydolphinscheduler/java_gateway.py
+++ b/src/pydolphinscheduler/java_gateway.py
@@ -103,7 +103,12 @@ class GatewayEntryPoint:
         return self.gateway.entry_point.getResourcesFileInfo(program_type, 
main_package)
 
     def create_or_update_resource(
-        self, project_name: str, user_name: str, name: str, content: str, 
description: Optional[str] = None
+        self,
+        project_name: str,
+        user_name: str,
+        name: str,
+        content: str,
+        description: Optional[str] = None,
     ):
         """Create or update resource through java gateway."""
         return self.gateway.entry_point.createOrUpdateResource(
diff --git a/src/pydolphinscheduler/models/datasource.py 
b/src/pydolphinscheduler/models/datasource.py
index 3b55f21..e0fbf9c 100644
--- a/src/pydolphinscheduler/models/datasource.py
+++ b/src/pydolphinscheduler/models/datasource.py
@@ -16,7 +16,6 @@
 # under the License.
 
 """Module database."""
-import json
 import re
 from typing import NamedTuple, Optional
 
@@ -69,7 +68,7 @@ class Datasource(metaclass=ModelMeta):
     """
 
     _PATTERN = re.compile(
-        
"jdbc:.*://(?P<host>[\\w\\W]+):(?P<port>\\d+)/(?P<database>[\\w\\W]+)\\?"
+        
"jdbc:.*://(?P<host>[\\w\\W]+):(?P<port>\\d+)/(?P<database>[\\w\\W]+)(?P<others>\\?.*|)"
     )
 
     _DATABASE_TYPE_MAP = dict(
@@ -129,18 +128,21 @@ class Datasource(metaclass=ModelMeta):
     @property
     def connection(self) -> Connection:
         """Parse dolphinscheduler datasource_config to Connection."""
-        data = json.loads(self.datasource_config)
 
-        pattern_match = self._PATTERN.match(
-            data.get("jdbcUrl", data.get("url", None))
-        ).groupdict()
+        if "jdbcUrl" in self.datasource_config:
+            jdbc_url = self.datasource_config.get("jdbcUrl")
+        elif "url" in self.datasource_config:
+            jdbc_url = self.datasource_config.get("url")
+        else:
+            raise ValueError("The datasource_config must contain jdbcUrl or 
url key.")
+        pattern_match = self._PATTERN.match(jdbc_url).groupdict()
 
         return Connection(
             host=pattern_match.get("host", None),
             port=int(pattern_match.get("port", None)),
             schema=pattern_match.get("database", None),
-            username=data.get("user", None),
-            password=data.get("password", None),
+            username=self.datasource_config.get("user", None),
+            password=self.datasource_config.get("password", None),
         )
 
     @property

Reply via email to