{"record":{"id":"b9833c994a2ce24f","repo":"apache/dolphinscheduler","slug":"workflow-define-state-online","errorCode":"WORKFLOW_DEFINE_STATE_ONLINE","errorMessage":"WORKFLOW_DEFINE_STATE_ONLINE: workflow definition [{name}] state is online, can not delete","messagePattern":"WORKFLOW_DEFINE_STATE_ONLINE: workflow definition \\[(.+?)\\] state is online, can not delete","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":849,"sourceCode":"                this.deleteWorkflowDefinitionByCode(loginUser, workflowDefinition.getCode());\n            } catch (Exception e) {\n                throw new ServiceException(Status.DELETE_WORKFLOW_DEFINE_ERROR, workflowDefinition.getName(),\n                        e.getMessage());\n            }\n        }\n    }\n\n    /**\n     * workflow definition want to delete whether used in other task, should throw exception when have be used.\n     * <p>\n     * This function avoid delete workflow definition already dependencies by other tasks by accident.\n     *\n     * @param workflowDefinition WorkflowDefinition you change task definition and task relation\n     */\n    private void workflowDefinitionUsedInOtherTaskValid(User loginUser, WorkflowDefinition workflowDefinition) {\n        // check workflow definition is already online\n        if (workflowDefinition.getReleaseState() == ReleaseState.ONLINE) {\n            throw new ServiceException(Status.WORKFLOW_DEFINE_STATE_ONLINE, workflowDefinition.getName());\n        }\n\n        // check workflow instances is already running\n        List<WorkflowInstanceSummaryDto> workflowInstances =\n                workflowInstanceService.queryByWorkflowDefinitionCodeAndStatus(\n                        workflowDefinition.getCode(), WorkflowExecutionStatus.NOT_TERMINAL_STATES);\n        if (CollectionUtils.isNotEmpty(workflowInstances)) {\n            throw new ServiceException(Status.DELETE_WORKFLOW_DEFINITION_EXECUTING_FAIL, workflowInstances.size());\n        }\n\n        // check workflow used by other task, including sub workflow and dependent task type\n        Optional<String> taskDepMsg = workflowLineageService.taskDependentMsg(loginUser,\n                workflowDefinition.getProjectCode(), workflowDefinition.getCode(), 0);\n\n        if (taskDepMsg.isPresent()) {\n            String errorMeg = \"workflow definition cannot be deleted because it has dependent, \" + taskDepMsg.get();\n            log.error(errorMeg);\n            throw new ServiceException(errorMeg);","sourceCodeStart":831,"sourceCodeEnd":867,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L831-L867","documentation":"workflowDefinitionUsedInOtherTaskValid throws this when the target workflow definition's release state is ONLINE. Deleting (or otherwise mutating) a released workflow is forbidden; it must first be taken OFFLINE via the release endpoint. This is an invalid-state-transition guard, not a data error.","triggerScenarios":"Calling deleteWorkflowDefinitionByCode / batch delete on a workflow that was published (releaseState=ONLINE) and never switched back to OFFLINE.","commonSituations":"CI scripts that delete workflows without releasing them first; users clicking delete on a running production workflow; migration scripts importing new versions while the old released one remains.","solutions":["Release the workflow to OFFLINE (workflowDefinitionService.releaseWorkflowDefinition) before deleting.","Confirm no scheduler is depending on it, then retry the delete.","If the state is stale/incorrect, fix the release state in the DB and re-attempt."],"exampleFix":"// before\nworkflowDefinitionService.deleteWorkflowDefinitionByCode(loginUser, code); // ONLINE -> throws\n// after\nworkflowDefinitionService.releaseWorkflowDefinition(loginUser, projectCode, code, ReleaseState.OFFLINE);\nworkflowDefinitionService.deleteWorkflowDefinitionByCode(loginUser, code);","handlingStrategy":"validation","validationCode":"WorkflowDefinition wf = workflowDefinitionDao.queryByCode(code)\n    .orElseThrow(NoSuchElementException::new);\nif (wf.getReleaseState() == ReleaseState.ONLINE) {\n    workflowDefinitionService.releaseWorkflowDefinition(user, projectCode, code, ReleaseState.OFFLINE);\n}","typeGuard":null,"tryCatchPattern":"try { service.deleteWorkflowDefinitionByCode(user, code); }\ncatch (ServiceException e) { if (e.getCode() == Status.WORKFLOW_DEFINE_STATE_ONLINE) { /* offline first, retry */ } }","preventionTips":["Always pair delete with an offline step in automation scripts","Check releaseState before any destructive call","Educate users that released workflows are protected"],"tags":["workflow-definition","release-state","state-guard"],"backgroundTag":"invalid-state-transition","analyzedSha":"02eac45a1b6676e639fcbfb4be2243de5771b05d","analyzedAt":"2026-09-06T17:43:00.555Z","contentChangedAt":"2026-09-06T17:43:00.555Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}