{"record":{"id":"5754481d2ed71a13","repo":"apache/dolphinscheduler","slug":"50040","errorCode":"50040","errorMessage":"Switch task definition version error","messagePattern":"Switch task definition version error","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java","lineNumber":221,"sourceCode":"                    ReleaseState.ONLINE.getDescp(), taskCode);\n            throw new ServiceException(Status.WORKFLOW_DEFINE_STATE_ONLINE);\n        }\n        TaskDefinition taskDefinition = taskDefinitionDao.queryByCode(taskCode);\n        if (taskDefinition == null || projectCode != taskDefinition.getProjectCode()) {\n            log.error(\"Task definition does not exist, taskDefinitionCode:{}.\", taskCode);\n            throw new ServiceException(Status.TASK_DEFINE_NOT_EXIST, String.valueOf(taskCode));\n        }\n        TaskDefinitionLog taskDefinitionUpdate =\n                taskDefinitionLogMapper.queryByDefinitionCodeAndVersion(taskCode, version);\n        taskDatasourcePermissionChecker.checkPermission(loginUser, Collections.singletonList(taskDefinitionUpdate));\n        taskSubWorkflowPermissionChecker.checkPermission(loginUser, Collections.singletonList(taskDefinitionUpdate));\n        taskDefinitionUpdate.setUserId(loginUser.getId());\n        taskDefinitionUpdate.setUpdateTime(new Date());\n        taskDefinitionUpdate.setId(taskDefinition.getId());\n        boolean switchSuccess = taskDefinitionDao.updateById(taskDefinitionUpdate);\n        if (!switchSuccess) {\n            log.error(\"Task definition version switch error, taskDefinitionCode:{}.\", taskCode);\n            throw new ServiceException(Status.SWITCH_TASK_DEFINITION_VERSION_ERROR);\n        }\n        List<WorkflowTaskRelation> taskRelationList =\n                workflowTaskRelationDao.queryUpstreamByCode(projectCode, taskCode);\n        if (CollectionUtils.isNotEmpty(taskRelationList)) {\n            log.info(\n                    \"Task definition has upstream tasks, start handle them after switch task, taskDefinitionCode:{}.\",\n                    taskCode);\n            long workflowDefinitionCode = taskRelationList.get(0).getWorkflowDefinitionCode();\n            List<WorkflowTaskRelation> workflowTaskRelations =\n                    workflowTaskRelationDao.queryByWorkflowDefinitionCode(workflowDefinitionCode);\n            updateDag(loginUser, workflowDefinitionCode, workflowTaskRelations,\n                    Lists.newArrayList(taskDefinitionUpdate));\n        } else {\n            log.info(\n                    \"Task definition version switch complete, switch task version to {}, taskDefinitionCode:{}.\",\n                    version, taskCode);\n        }\n    }","sourceCodeStart":203,"sourceCodeEnd":239,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java#L203-L239","documentation":"Thrown in switchVersion when taskDefinitionDao.queryByCode returns null or the task's projectCode differs from the requested projectCode. Either the task code is unknown or the task belongs to another project, so the version switch is refused to prevent cross-project modification.","triggerScenarios":"Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:221 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Verify the task code and that it belongs to the given projectCode.","Confirm the task definition was not deleted.","Query the task list for the project to get the correct code."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}