{"record":{"id":"028c221945ed9463","repo":"apache/dolphinscheduler","slug":"switch-workflow-definition-version-not-exist-workf","errorCode":"SWITCH_WORKFLOW_DEFINITION_VERSION_NOT_EXIST_WORKFLOW_DEFINITION_ERROR","errorMessage":"SWITCH_WORKFLOW_DEFINITION_VERSION_NOT_EXIST_WORKFLOW_DEFINITION_ERROR: switch workflow definition version error because workflow definition [{0}] does not exist","messagePattern":"SWITCH_WORKFLOW_DEFINITION_VERSION_NOT_EXIST_WORKFLOW_DEFINITION_ERROR: switch workflow definition version error because workflow definition \\[(.+?)\\] does not exist","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":1592,"sourceCode":"     * @param loginUser   login user\n     * @param projectCode project code\n     * @param code        workflow definition code\n     * @param version     the version user want to switch\n     * @return switch workflow definition version result code\n     */\n    @Override\n    @Transactional\n    public void switchWorkflowDefinitionVersion(User loginUser, long projectCode, long code,\n                                                int version) {\n        Project project = projectDao.queryByCode(projectCode);\n        projectService.checkHasProjectWritePermissionThrowException(loginUser, project);\n\n        WorkflowDefinition workflowDefinition = workflowDefinitionDao.queryByCode(code).orElse(null);\n        if (Objects.isNull(workflowDefinition) || projectCode != workflowDefinition.getProjectCode()) {\n            log.error(\n                    \"Switch workflow definition error because it does not exist, projectCode:{}, workflowDefinitionCode:{}.\",\n                    projectCode, code);\n            throw new ServiceException(Status.SWITCH_WORKFLOW_DEFINITION_VERSION_NOT_EXIST_WORKFLOW_DEFINITION_ERROR,\n                    code);\n        }\n\n        WorkflowDefinitionLog workflowDefinitionLog =\n                workflowDefinitionLogMapper.queryByDefinitionCodeAndVersion(code, version);\n        if (Objects.isNull(workflowDefinitionLog)) {\n            log.error(\n                    \"Switch workflow definition error because version does not exist, projectCode:{}, workflowDefinitionCode:{}, version:{}.\",\n                    projectCode, code, version);\n            throw new ServiceException(\n                    Status.SWITCH_WORKFLOW_DEFINITION_VERSION_NOT_EXIST_WORKFLOW_DEFINITION_VERSION_ERROR,\n                    workflowDefinition.getCode(), version);\n        }\n        List<WorkflowTaskRelation> workflowTaskRelationList = workflowTaskRelationDao\n                .queryWorkflowTaskRelationsByWorkflowDefinitionCode(workflowDefinitionLog.getCode(),\n                        workflowDefinitionLog.getVersion());\n        List<TaskCodeVersionDto> taskDefinitionList = getTaskCodeVersionDtos(workflowTaskRelationList);\n        List<TaskDefinitionLog> taskDefinitionLogList =","sourceCodeStart":1574,"sourceCodeEnd":1610,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L1574-L1610","documentation":"Thrown by switchWorkflowDefinitionVersion when the workflow definition identified by `code` does not exist, or exists but does not belong to the given projectCode. The API cannot switch the version of a workflow it cannot find in the expected project. The workflow code is interpolated into the localized message.","triggerScenarios":"Calling POST /dolphinscheduler/projects/{projectCode}/workflow-definition/{code}/version/switch (or switchWorkflowDefinitionVersion) with a stale/wrong workflow code, or a code belonging to a different project than the projectCode path parameter.","commonSituations":"Using a workflow code copied from another environment (codes are generated per-instance); the workflow was deleted before the switch; passing projectCode/code swapped or mismatched; scripting against the API with an outdated code list.","solutions":["Verify the workflow code exists and matches: GET /dolphinscheduler/projects/{projectCode}/workflow-definition/list and compare codes.","Confirm the code belongs to the same projectCode you pass in the URL — project mismatch triggers this error even if the code exists.","If the workflow was deleted, re-create it or pick the correct code; no version switch is possible on a deleted definition.","Refresh your automation's stored workflow codes after re-imports, since new imports get newly generated codes."],"exampleFix":"// before: switchWorkflowDefinitionVersion(user, 42L, 99999999999999L, 3) // code not in project 42\n// after: resolve real code first\nlong code = workflowList.stream().filter(w -> \"my_wf\".equals(w.getName())).findFirst().get().getCode();\nswitchWorkflowDefinitionVersion(user, 42L, code, 3);","handlingStrategy":"validation","validationCode":"boolean workflowExistsInProject(long projectCode, long code) {\n    return workflowDefinitionDao.queryByCode(code)\n        .map(wf -> wf.getProjectCode() == projectCode)\n        .orElse(false);\n}\n// call before switchWorkflowDefinitionVersion","typeGuard":null,"tryCatchPattern":"try {\n    workflowDefinitionService.switchWorkflowDefinitionVersion(user, projectCode, code, version);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.SWITCH_WORKFLOW_DEFINITION_VERSION_NOT_EXIST_WORKFLOW_DEFINITION_ERROR) {\n        // re-list workflows to get the current code / confirm project\n    }\n}","preventionTips":["Fetch workflow codes dynamically from the list API instead of hard-coding them.","Never reuse codes across environments — codes are generated per instance.","Confirm projectCode and code together; a code from another project raises this same error.","Handle deleted workflows in automation before attempting version switches."],"tags":["workflow-version","not-found","rest-api","project-mismatch"],"backgroundTag":"entity-not-found","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"}