{"record":{"id":"25a6f5ab30370365","repo":"apache/dolphinscheduler","slug":"50026","errorCode":"50026","errorMessage":"batch delete workflow definition by codes error: {0}","messagePattern":"batch delete workflow definition by codes error: (.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java","lineNumber":824,"sourceCode":"    public void batchDeleteWorkflowDefinitionByCodes(User loginUser, long projectCode, String codes) {\n        if (StringUtils.isEmpty(codes)) {\n            log.error(\"Parameter workflowDefinitionCodes is empty, projectCode is {}.\", projectCode);\n            throw new ServiceException(Status.WORKFLOW_DEFINITION_CODES_IS_EMPTY);\n        }\n\n        Set<Long> definitionCodes = Lists.newArrayList(codes.split(Constants.COMMA)).stream().map(Long::parseLong)\n                .collect(Collectors.toSet());\n        List<WorkflowDefinition> workflowDefinitionList = workflowDefinitionDao.queryByCodes(definitionCodes);\n        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.","sourceCodeStart":806,"sourceCodeEnd":842,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkflowDefinitionServiceImpl.java#L806-L842","documentation":"Thrown by batchDeleteWorkflowDefinitionByCodes when one or more of the submitted workflow definition codes do not exist in the project. The service computes the set difference between the requested codes and the codes actually found in the database; a non-empty difference means 'resource not found' for part of the batch, and the whole batch is aborted. The error message embeds the offending codes.","triggerScenarios":"Calling batchDeleteWorkflowDefinitionByCodes with codes that were already deleted, belong to another project, were mistyped, or were fetched in a stale UI listing before another user deleted them.","commonSituations":"Double-delete from concurrent sessions or retried API calls; deleting workflows in a batch where one was removed moments earlier; copying codes from a different project's export; stale frontend caches after an admin purge.","solutions":["Query each code first (workflowDefinitionDao.queryByCode) and remove nonexistent codes from the batch before calling the API.","Re-fetch the workflow list to refresh codes and retry only with codes that still exist.","Verify the codes belong to the correct project code you are operating on."],"exampleFix":"// before\nworkflowDefinitionService.batchDeleteWorkflowDefinitionByCodes(loginUser, projectCode, Arrays.asList(1L, 2L, 3L));\n// after\nList<Long> valid = codes.stream()\n    .filter(c -> workflowDefinitionDao.queryByCode(c).isPresent())\n    .collect(Collectors.toList());\nworkflowDefinitionService.batchDeleteWorkflowDefinitionByCodes(loginUser, projectCode, valid);","handlingStrategy":"validation","validationCode":"Set<Long> existing = codes.stream()\n    .filter(c -> workflowDefinitionDao.queryByCode(c).isPresent())\n    .collect(Collectors.toSet());\nif (!existing.equals(new HashSet<>(codes))) throw new IllegalArgumentException(\"some codes do not exist\");","typeGuard":null,"tryCatchPattern":"try { service.batchDeleteWorkflowDefinitionByCodes(user, projectCode, codes); }\ncatch (ServiceException e) { /* parse nonexistent codes from e.getMessage() and resubmit valid subset */ }","preventionTips":["Always resolve codes from a fresh listWorkflows query","Make delete calls idempotent on the caller side (ignore already-missing codes)","Avoid sharing code lists across projects"],"tags":["batch-delete","workflow-definition","not-found","input-validation"],"backgroundTag":"resource-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"}