{"record":{"id":"e531e4ec1804d366","repo":"apache/dolphinscheduler","slug":"delete-schedule-by-id-error-e531e4","errorCode":"DELETE_SCHEDULE_BY_ID_ERROR","errorMessage":"DELETE_SCHEDULE_BY_ID_ERROR: delete schedule by id error","messagePattern":"DELETE_SCHEDULE_BY_ID_ERROR: delete schedule by id error","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":891,"sourceCode":"                .orElseThrow(() -> new ServiceException(WORKFLOW_DEFINITION_NOT_EXIST, String.valueOf(code)));\n\n        Project project = projectDao.queryByCode(workflowDefinition.getProjectCode());\n        projectService.checkHasProjectWritePermissionThrowException(loginUser, project);\n\n        // Determine if the login user is the owner of the workflow definition\n        if (loginUser.getId() != workflowDefinition.getUserId() && loginUser.getUserType() != UserType.ADMIN_USER) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        workflowDefinitionUsedInOtherTaskValid(loginUser, workflowDefinition);\n\n        // get the timing according to the workflow definition\n        Schedule scheduleObj = scheduleDao.queryByWorkflowDefinitionCode(code);\n        if (scheduleObj != null) {\n            if (scheduleObj.getReleaseState() == ReleaseState.OFFLINE) {\n                boolean delete = scheduleDao.deleteById(scheduleObj.getId());\n                if (!delete) {\n                    throw new ServiceException(Status.DELETE_SCHEDULE_BY_ID_ERROR);\n                }\n            }\n            if (scheduleObj.getReleaseState() == ReleaseState.ONLINE) {\n                throw new ServiceException(Status.SCHEDULE_STATE_ONLINE, scheduleObj.getId());\n            }\n        }\n\n        // delete workflow instance, will delete workflow instance, sub workflow instance, task instance, alert\n        workflowInstanceService.deleteWorkflowInstanceByWorkflowDefinitionCode(workflowDefinition.getCode());\n        // delete task definition\n        taskDefinitionService.deleteTaskByWorkflowDefinitionCode(workflowDefinition.getCode(),\n                workflowDefinition.getVersion());\n        // delete task definition log\n        taskDefinitionLogService.deleteTaskByWorkflowDefinitionCode(workflowDefinition.getCode());\n        // delete workflow definition log\n        workflowDefinitionLogDao.deleteByWorkflowDefinitionCode(workflowDefinition.getCode());\n\n        // we delete the workflow definition at last to avoid using transaction here.","sourceCodeStart":873,"sourceCodeEnd":909,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L873-L909","documentation":"Thrown when deleting a workflow whose OFFLINE schedule record fails to be removed from the database (scheduleDao.deleteById returns false). The workflow delete aborts because the timing (schedule) row could not be cleaned up — typically a persistence-layer failure.","triggerScenarios":"scheduleDao.deleteById returning false due to DB connectivity problems, transaction conflicts, row already deleted concurrently, or constraint violations.","commonSituations":"Database under heavy load or transient connection loss; two operators deleting the same workflow simultaneously; replica/transaction issues in the metadata DB.","solutions":["Check the metadata DB connectivity and error logs, then retry the delete.","Verify the schedule row still exists (SCHEDULE_ID) and whether it was deleted by a concurrent operation.","Manually remove the orphaned schedule row, then complete the workflow deletion."],"exampleFix":"// before\nboolean delete = scheduleDao.deleteById(scheduleObj.getId());\nif (!delete) { throw new ServiceException(Status.DELETE_SCHEDULE_BY_ID_ERROR); }\n// after\nboolean delete = scheduleDao.deleteById(scheduleObj.getId());\nif (!delete && scheduleDao.queryById(scheduleObj.getId()) != null) {\n    throw new ServiceException(Status.DELETE_SCHEDULE_BY_ID_ERROR);\n} // treat already-gone row as idempotent success","handlingStrategy":"retry","validationCode":"// verify DB reachable and schedule row exists\nSchedule s = scheduleDao.queryByWorkflowDefinitionCode(code);\nboolean dbUp = dataSource.getConnection().isValid(3);","typeGuard":null,"tryCatchPattern":"try { service.deleteWorkflowDefinitionByCode(user, code); }\ncatch (ServiceException e) { if (e.getCode() == Status.DELETE_SCHEDULE_BY_ID_ERROR) { /* retry after checking DB health */ } }","preventionTips":["Monitor metadata DB connectivity","Avoid concurrent deletes of the same workflow","Clean up orphaned schedule rows after failures"],"tags":["schedule","database","delete-failed"],"backgroundTag":"database-write-failed","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"}