Browse Source

[python] Fix task procedure define error (#7407)

Cause procedure parameter name need `method` instead of `sql`
we change it's name. And remove parameter `sql` from parent
class `Database`

closes: #7386
3.0.0/version-upgrade
Jiajie Zhong 3 years ago committed by GitHub
parent
commit
4988004150
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 5
      dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/database.py
  2. 9
      dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/procedure.py
  3. 3
      dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py
  4. 7
      dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_database.py
  5. 6
      dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_procedure.py

5
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/database.py

@ -40,14 +40,11 @@ class Database(Task):
database type and database instance would run this sql. database type and database instance would run this sql.
""" """
_task_custom_attr = {"sql"}
def __init__( def __init__(
self, task_type: str, name: str, datasource_name: str, sql: str, *args, **kwargs self, task_type: str, name: str, datasource_name: str, *args, **kwargs
): ):
super().__init__(name, task_type, *args, **kwargs) super().__init__(name, task_type, *args, **kwargs)
self.datasource_name = datasource_name self.datasource_name = datasource_name
self.sql = sql
self._datasource = {} self._datasource = {}
def get_datasource_type(self) -> str: def get_datasource_type(self) -> str:

9
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/procedure.py

@ -37,7 +37,8 @@ class Procedure(Database):
database type and database instance would run this sql. database type and database instance would run this sql.
""" """
def __init__(self, name: str, datasource_name: str, sql: str, *args, **kwargs): _task_custom_attr = {"method"}
super().__init__(
TaskType.PROCEDURE, name, datasource_name, sql, *args, **kwargs def __init__(self, name: str, datasource_name: str, method: str, *args, **kwargs):
) super().__init__(TaskType.PROCEDURE, name, datasource_name, *args, **kwargs)
self.method = method

3
dolphinscheduler-python/pydolphinscheduler/src/pydolphinscheduler/tasks/sql.py

@ -66,7 +66,8 @@ class Sql(Database):
*args, *args,
**kwargs **kwargs
): ):
super().__init__(TaskType.SQL, name, datasource_name, sql, *args, **kwargs) super().__init__(TaskType.SQL, name, datasource_name, *args, **kwargs)
self.sql = sql
self.pre_statements = pre_statements or [] self.pre_statements = pre_statements or []
self.post_statements = post_statements or [] self.post_statements = post_statements or []
self.display_rows = display_rows self.display_rows = display_rows

7
dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_database.py

@ -55,12 +55,10 @@ def test_get_datasource_detail(mock_datasource, mock_code_version):
"task_type": TEST_DATABASE_TASK_TYPE, "task_type": TEST_DATABASE_TASK_TYPE,
"name": "test-task-params", "name": "test-task-params",
"datasource_name": TEST_DATABASE_DATASOURCE_NAME, "datasource_name": TEST_DATABASE_DATASOURCE_NAME,
"sql": TEST_DATABASE_SQL,
}, },
{ {
"type": "MYSQL", "type": "MYSQL",
"datasource": 1, "datasource": 1,
"sql": TEST_DATABASE_SQL,
"localParams": [], "localParams": [],
"resourceList": [], "resourceList": [],
"dependence": {}, "dependence": {},
@ -105,7 +103,6 @@ def test_database_get_define(mock_datasource, mock_code_version):
"taskParams": { "taskParams": {
"type": "MYSQL", "type": "MYSQL",
"datasource": 1, "datasource": 1,
"sql": TEST_DATABASE_SQL,
"localParams": [], "localParams": [],
"resourceList": [], "resourceList": [],
"dependence": {}, "dependence": {},
@ -121,7 +118,5 @@ def test_database_get_define(mock_datasource, mock_code_version):
"timeoutNotifyStrategy": None, "timeoutNotifyStrategy": None,
"timeout": 0, "timeout": 0,
} }
task = Database( task = Database(TEST_DATABASE_TASK_TYPE, name, TEST_DATABASE_DATASOURCE_NAME)
TEST_DATABASE_TASK_TYPE, name, TEST_DATABASE_DATASOURCE_NAME, TEST_DATABASE_SQL
)
assert task.get_define() == expect assert task.get_define() == expect

6
dolphinscheduler-python/pydolphinscheduler/tests/tasks/test_procedure.py

@ -52,10 +52,10 @@ def test_get_datasource_detail(mock_datasource, mock_code_version):
{ {
"name": "test-procedure-task-params", "name": "test-procedure-task-params",
"datasource_name": TEST_PROCEDURE_DATASOURCE_NAME, "datasource_name": TEST_PROCEDURE_DATASOURCE_NAME,
"sql": TEST_PROCEDURE_SQL, "method": TEST_PROCEDURE_SQL,
}, },
{ {
"sql": TEST_PROCEDURE_SQL, "method": TEST_PROCEDURE_SQL,
"type": "MYSQL", "type": "MYSQL",
"datasource": 1, "datasource": 1,
"localParams": [], "localParams": [],
@ -102,7 +102,7 @@ def test_sql_get_define(mock_datasource, mock_code_version):
"taskParams": { "taskParams": {
"type": "MYSQL", "type": "MYSQL",
"datasource": 1, "datasource": 1,
"sql": TEST_PROCEDURE_SQL, "method": TEST_PROCEDURE_SQL,
"localParams": [], "localParams": [],
"resourceList": [], "resourceList": [],
"dependence": {}, "dependence": {},

Loading…
Cancel
Save