You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@dolphinscheduler.apache.org by "ruanwenjun (via GitHub)" <gi...@apache.org> on 2026/05/08 06:00:06 UTC

[PR] [Improvement-18224][API] Migrate TaskDefinitionService Map returns to typed returns [dolphinscheduler]

ruanwenjun opened a new pull request, #18229:
URL: https://github.com/apache/dolphinscheduler/pull/18229

   <!--Thanks very much for contributing to Apache DolphinScheduler, we are happy that you want to help us improve DolphinScheduler! -->
   
   ## Was this PR generated or assisted by AI?
   
   YES, ops 4.7
   
   ## Purpose of the pull request
   
   Refactor 7 TaskDefinitionService methods from Map<String, Object> to typed return / void + ServiceException, with cascading updates to controller, PythonGateway and unit test:
   
   - queryTaskDefinitionByName(...): TaskDefinition
   - updateTaskWithUpstream(...): Long (the updated task code)
   - switchVersion(...): void
   - deleteByCodeAndVersion(...): void
   - queryTaskDefinitionDetail(...): TaskDefinitionVO
   - genTaskCodeList(Integer): List<Long>
   - releaseTaskDefinition(...): void
   
   The private updateTask helper now throws ServiceException for every error path; it still returns null for the "task body unchanged" case so the public method can short-circuit when both the body and upstream relations are unchanged. As a side effect this fixes a latent bug in updateTaskWithUpstream where any error from the helper was silently overridden with SUCCESS whenever the new and existing upstream code sets happened to match (e.g. TASK_DEFINE_NOT_EXIST returned 200 OK). No test covered that edge case.
   
   A small private helper requireProjectAndWritePerm replaces the inline hasProjectAndWritePerm(Map) call sites; ProjectService remains untouched and will be migrated last in the #18224 series.
   
   HTTP wire format is preserved: ApiExceptionHandler converts ServiceException to the same Result(code, msg) shape that BaseController.returnDataList(map) produced; success paths use Result.success(data) matching the prior JSON body byte-for-byte.
   
   Py4J boundary is preserved: PythonGateway.genTaskCodeList still returns Map<String, Object> with the same {STATUS, MSG, DATA_LIST} keys, now constructed in the wrapper from the service's typed return.
   
   Part of the migration series tracked by #18224.
   
   ## Brief change log
   
   <!--*(for example:)*
   - *Add maven-checkstyle-plugin to root pom.xml*
   -->
   
   ## Verify this pull request
   
   <!--*(Please pick either of the following options)*-->
   
   This pull request is code cleanup without any test coverage.
   
   *(or)*
   
   This pull request is already covered by existing tests, such as *(please describe tests)*.
   
   (or)
   
   This change added tests and can be verified as follows:
   
   <!--*(example:)*
   - *Added dolphinscheduler-dao tests for end-to-end.*
   - *Added CronUtilsTest to verify the change.*
   - *Manually verified the change by testing locally.* -->
   
   (or)
   
   ## Pull Request Notice
   [Pull Request Notice](https://github.com/apache/dolphinscheduler/blob/dev/docs/docs/en/contribute/join/pull-request.md)
   
   If your pull request contains incompatible change, you should also add it to `docs/docs/en/guide/upgrade/incompatible.md`
   


-- 
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@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-18224][API] Migrate TaskDefinitionService Map returns to typed returns [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #18229:
URL: https://github.com/apache/dolphinscheduler/pull/18229#issuecomment-4414935880

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=18229) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=18229&metric=new_coverage&view=list) (required ≥ 60%)  
     
   <!-- sqra:qg_revision=2b2b8738f5df9a73dc03dca83b6ce66a759a59dcb47b015979900e64e3585c8d -->
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=18229)
   
   


-- 
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@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-18224][API] Migrate TaskDefinitionService Map returns to typed returns [dolphinscheduler]

Posted by "github-advanced-security[bot] (via GitHub)" <gi...@apache.org>.
github-advanced-security[bot] commented on code in PR #18229:
URL: https://github.com/apache/dolphinscheduler/pull/18229#discussion_r3206677809


##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java:
##########
@@ -141,12 +142,12 @@
     @ResponseStatus(HttpStatus.OK)
     @ApiException(SWITCH_TASK_DEFINITION_VERSION_ERROR)
     @OperatorLog(auditType = AuditType.TASK_SWITCH_VERSION)
-    public Result switchTaskDefinitionVersion(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
-                                              @Parameter(name = "projectCode", description = "PROJECT_CODE", required = true) @PathVariable long projectCode,
-                                              @PathVariable(value = "code") long code,
-                                              @PathVariable(value = "version") int version) {
-        Map<String, Object> result = taskDefinitionService.switchVersion(loginUser, projectCode, code, version);
-        return returnDataList(result);
+    public Result<Void> switchTaskDefinitionVersion(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,

Review Comment:
   ## CodeQL / HTTP request type unprotected from CSRF
   
   Potential CSRF vulnerability due to using an HTTP request type which is not default-protected from CSRF for an apparent [state-changing action](1).
   Potential CSRF vulnerability due to using an HTTP request type which is not default-protected from CSRF for an apparent [state-changing action](2).
   Potential CSRF vulnerability due to using an HTTP request type which is not default-protected from CSRF for an apparent [state-changing action](3).
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/5771)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/controller/TaskDefinitionController.java:
##########
@@ -212,10 +213,10 @@
     @GetMapping(value = "/gen-task-codes")
     @ResponseStatus(HttpStatus.OK)
     @ApiException(LOGIN_USER_QUERY_PROJECT_LIST_PAGING_ERROR)
-    public Result genTaskCodeList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,
-                                  @RequestParam("genNum") Integer genNum) {
-        Map<String, Object> result = taskDefinitionService.genTaskCodeList(genNum);
-        return returnDataList(result);
+    public Result<List<Long>> genTaskCodeList(@Parameter(hidden = true) @RequestAttribute(value = Constants.SESSION_USER) User loginUser,

Review Comment:
   ## CodeQL / Useless parameter
   
   The parameter 'loginUser' is never used.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/5773)



##########
dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:
##########
@@ -130,23 +130,33 @@
      * @param taskName    task name
      */
     @Override
-    public Map<String, Object> queryTaskDefinitionByName(User loginUser, long projectCode, long workflowDefinitionCode,
-                                                         String taskName) {
+    public TaskDefinition queryTaskDefinitionByName(User loginUser, long projectCode, long workflowDefinitionCode,
+                                                    String taskName) {
         Project project = projectMapper.queryByCode(projectCode);
         // check user access for project
         projectService.checkProjectAndAuthThrowException(loginUser, project, TASK_DEFINITION);
 
-        Map<String, Object> result = new HashMap<>();
         TaskDefinition taskDefinition =
                 taskDefinitionMapper.queryByName(project.getCode(), workflowDefinitionCode, taskName);
         if (taskDefinition == null) {
             log.error("Task definition does not exist, taskName:{}.", taskName);
-            putMsg(result, Status.TASK_DEFINE_NOT_EXIST, taskName);
-        } else {
-            result.put(Constants.DATA_LIST, taskDefinition);
-            putMsg(result, Status.SUCCESS);
+            throw new ServiceException(Status.TASK_DEFINE_NOT_EXIST, taskName);
+        }
+        return taskDefinition;
+    }
+
+    /**
+     * Resolve project + write permission; throws ServiceException with the
+     * status that {@link ProjectService#hasProjectAndWritePerm(User, Project, Map)}
+     * would otherwise have written into the legacy result map.
+     */
+    private void requireProjectAndWritePerm(User loginUser, Project project) {
+        Map<String, Object> permCheck = new HashMap<>();
+        if (!projectService.hasProjectAndWritePerm(loginUser, project, permCheck)) {

Review Comment:
   ## CodeQL / Deprecated method or constructor invocation
   
   Invoking [ProjectService.hasProjectAndWritePerm](1) should be avoided because it has been deprecated.
   
   [Show more details](https://github.com/apache/dolphinscheduler/security/code-scanning/5772)



-- 
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@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-18224][API] Migrate TaskDefinitionService Map returns to typed returns [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #18229:
URL: https://github.com/apache/dolphinscheduler/pull/18229#issuecomment-4414575411

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=18229) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=18229&metric=new_coverage&view=list) (required ≥ 60%)  
     
   <!-- sqra:qg_revision=2b2b8738f5df9a73dc03dca83b6ce66a759a59dcb47b015979900e64e3585c8d -->
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=18229)
   
   


-- 
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@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-18224][API] Migrate TaskDefinitionService Map returns to typed returns [dolphinscheduler]

Posted by "ruanwenjun (via GitHub)" <gi...@apache.org>.
ruanwenjun merged PR #18229:
URL: https://github.com/apache/dolphinscheduler/pull/18229


-- 
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@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] [Improvement-18224][API] Migrate TaskDefinitionService Map returns to typed returns [dolphinscheduler]

Posted by "sonarqubecloud[bot] (via GitHub)" <gi...@apache.org>.
sonarqubecloud[bot] commented on PR #18229:
URL: https://github.com/apache/dolphinscheduler/pull/18229#issuecomment-4404026666

   ## [![Quality Gate Failed](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/checks/QualityGateBadge/qg-failed-20px.png 'Quality Gate Failed')](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=18229) **Quality Gate failed**  
   Failed conditions  
   ![](https://sonarsource.github.io/sonarcloud-github-static-resources/v2/common/failed-16px.png '') [0.0% Coverage on New Code](https://sonarcloud.io/component_measures?id=apache-dolphinscheduler&pullRequest=18229&metric=new_coverage&view=list) (required ≥ 60%)  
     
   <!-- sqra:qg_revision=2b2b8738f5df9a73dc03dca83b6ce66a759a59dcb47b015979900e64e3585c8d -->
   <!-- sqra-placement-anchor -->
   [See analysis details on SonarQube Cloud](https://sonarcloud.io/dashboard?id=apache-dolphinscheduler&pullRequest=18229)
   
   


-- 
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@dolphinscheduler.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org