{"record":{"id":"dce16aaf7f40d378","repo":"apache/dolphinscheduler","slug":"50060","errorCode":"50060","errorMessage":"delete workflow definition [{0}] error: {1}","messagePattern":"delete workflow definition \\[(.+?)\\] error: (.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":833,"sourceCode":"        Set<Long> queryCodes =\n                workflowDefinitionList.stream().map(WorkflowDefinition::getCode).collect(Collectors.toSet());\n        // definitionCodes - queryCodes\n        Set<Long> diffCode =\n                definitionCodes.stream().filter(code -> !queryCodes.contains(code)).collect(Collectors.toSet());\n\n        if (CollectionUtils.isNotEmpty(diffCode)) {\n            log.error(\"workflow definition does not exist, workflowDefinitionCodes:{}.\",\n                    diffCode.stream().map(String::valueOf).collect(Collectors.joining(Constants.COMMA)));\n            throw new ServiceException(Status.BATCH_DELETE_WORKFLOW_DEFINE_BY_CODES_ERROR,\n                    diffCode.stream().map(code -> code + \"[workflow definition not exist]\")\n                            .collect(Collectors.joining(Constants.COMMA)));\n        }\n\n        for (WorkflowDefinition workflowDefinition : workflowDefinitionList) {\n            try {\n                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","sourceCodeStart":815,"sourceCodeEnd":851,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L815-L851","documentation":"Wrapping error in batchDeleteWorkflowDefinitionByCodes: the per-code deleteWorkflowDefinitionByCode call threw, so the loop rethrows a ServiceException carrying the workflow name and the underlying cause message. It indicates one workflow in the batch failed its individual delete (state, dependency, or DB failure).","triggerScenarios":"Batch delete where any single workflow fails its internal checks or DB operations — e.g. its sub-delete threw DELETE_SCHEDULE_BY_ID_ERROR, lineage delete failure, or a database write error.","commonSituations":"Batch containing a workflow with an online schedule or running instances deeper in the chain; DB connectivity issues mid-loop; foreign-key constraint from task definitions.","solutions":["Read the embedded cause message ({1}) to identify the specific workflow and underlying failure, then fix that condition (offline the schedule, stop instances).","Delete workflows individually to isolate the failing one.","Check database connectivity/constraints if the cause is a persistence error and retry after the batch partially deleted."],"exampleFix":"// before\nservice.batchDeleteWorkflowDefinitionByCodes(loginUser, projectCode, allCodes); // fails on one bad workflow\n// after\nfor (Long code : allCodes) {\n    try {\n        service.deleteWorkflowDefinitionByCode(loginUser, code);\n    } catch (ServiceException e) {\n        log.warn(\"skipping workflow {}: {}\", code, e.getMessage());\n    }\n}","handlingStrategy":"try-catch","validationCode":"List<Long> deletable = codes.stream()\n    .filter(c -> workflowDefinitionDao.queryByCode(c).isPresent())\n    .collect(Collectors.toList());","typeGuard":null,"tryCatchPattern":"try { service.batchDeleteWorkflowDefinitionByCodes(user, projectCode, codes); }\ncatch (ServiceException e) { log.error(\"batch delete failed: {}\", e.getMessage(), e); /* fall back to per-code delete */ }","preventionTips":["Delete individually to isolate failures","Check schedules and running instances for every code before batching","Monitor DB health before large batch deletes"],"tags":["batch-delete","workflow-definition","wrapped-exception"],"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"}