{"record":{"id":"e1f7a92bf5fa7754","repo":"apache/dolphinscheduler","slug":"50021","errorCode":"50021","errorMessage":"workflow definition [{0}] is already online","messagePattern":"workflow definition \\[(.+?)\\] is already online","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java","lineNumber":204,"sourceCode":"    /**\n     * switch task definition\n     *\n     * @param loginUser   login user\n     * @param projectCode project code\n     * @param taskCode    task code\n     * @param version     the version user want to switch\n     */\n    @Transactional\n    @Override\n    public void switchVersion(User loginUser, long projectCode, long taskCode, int version) {\n        Project project = projectDao.queryByCode(projectCode);\n        projectService.checkHasProjectWritePermissionThrowException(loginUser, project);\n\n        if (processService.isTaskOnline(taskCode)) {\n            log.warn(\n                    \"Task definition version can not be switched due to workflow definition is {}, taskDefinitionCode:{}.\",\n                    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        }","sourceCodeStart":186,"sourceCodeEnd":222,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java#L186-L222","documentation":"Thrown in switchVersion when processService.isTaskOnline(taskCode) reports the task is currently used by an ONLINE (released) workflow definition. Switching versions of a task that is live in a published workflow is forbidden; the task must be taken offline first.","triggerScenarios":"Thrown at dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/TaskDefinitionServiceImpl.java:204 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Set the workflow definition to OFFLINE, then switch the task version, then re-publish.","Choose a task that is not part of an online workflow.","Inform the workflow owner that the change requires taking the workflow offline."],"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"}