{"record":{"id":"95f25309995ea026","repo":"apache/dolphinscheduler","slug":"assign-worker-group-to-project-error","errorCode":"ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR","errorMessage":"ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR: assign worker group to project error","messagePattern":"ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR: assign worker group to project error","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java","lineNumber":163,"sourceCode":"\n        if (CollectionUtils.isNotEmpty(needDeletedWorkerGroups)) {\n            Set<String> usedWorkerGroups = getAllUsedWorkerGroups(project);\n            if (CollectionUtils.isNotEmpty(usedWorkerGroups) && CollectionUtils.isNotEmpty(needDeletedWorkerGroups)) {\n                Set<String> shouldNotDelete = SetUtils.intersection(usedWorkerGroups, needDeletedWorkerGroups);\n                if (CollectionUtils.isNotEmpty(shouldNotDelete)) {\n                    throw new ServiceException(Status.USED_WORKER_GROUP_EXISTS, shouldNotDelete);\n                }\n            }\n            boolean deleted =\n                    projectWorkerGroupDao.deleteByProjectCodeAndWorkerGroups(projectCode,\n                            new ArrayList<>(needDeletedWorkerGroups));\n            if (deleted) {\n                log.info(\"Success to delete worker groups [{}] for the project [{}] .\", needDeletedWorkerGroups,\n                        project.getName());\n            } else {\n                log.error(\"Failed to delete worker groups [{}] for the project [{}].\", needDeletedWorkerGroups,\n                        project.getName());\n                throw new ServiceException(Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR);\n            }\n        }\n\n        Set<String> needAssignedWorkerGroups =\n                SetUtils.difference(unauthorizedWorkerGroupNames, projectWorkerGroupNames);\n        if (CollectionUtils.isNotEmpty(needAssignedWorkerGroups)) {\n            needAssignedWorkerGroups.forEach(workerGroupName -> {\n                ProjectWorkerGroup projectWorkerGroup = new ProjectWorkerGroup();\n                projectWorkerGroup.setProjectCode(projectCode);\n                projectWorkerGroup.setWorkerGroup(workerGroupName);\n                projectWorkerGroup.setCreateTime(now);\n                projectWorkerGroup.setUpdateTime(now);\n                int create = projectWorkerGroupDao.insert(projectWorkerGroup);\n                if (create > 0) {\n                    log.info(\"Success to add worker group [{}] for the project [{}] .\", workerGroupName,\n                            project.getName());\n                } else {\n                    log.error(\"Failed to add worker group [{}] for the project [{}].\", workerGroupName,","sourceCodeStart":145,"sourceCodeEnd":181,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/ProjectWorkerGroupRelationServiceImpl.java#L145-L181","documentation":"Thrown when deletion of project worker-group relations succeeded partially or failed (projectWorkerGroupDao.deleteByProjectCodeAndWorkerGroups returned false), meaning the assign operation could not complete. Indicates a persistence failure rather than a validation error.","triggerScenarios":"deleteByProjectCodeAndWorkerGroups returns false (no rows affected / DB issue) after passing the in-use validation, inside assignWorkerGroupsToProject.","commonSituations":"Database connection issues; the rows were already deleted by a concurrent request (0 rows affected treated as failure); transaction conflicts.","solutions":["Check DB connectivity and server logs for the preceding 'Failed to delete worker groups' error","Verify the relation rows still exist (maybe already deleted — the operation may effectively be done)","Retry the assignment; make deletion idempotent if races are the cause"],"exampleFix":"// before\nboolean deleted = projectWorkerGroupDao.deleteByProjectCodeAndWorkerGroups(projectCode, groups);\nif (deleted) { ... } else { throw new ServiceException(Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR); }\n// after\nprojectWorkerGroupDao.deleteByProjectCodeAndWorkerGroups(projectCode, groups); // treat 0 rows as success/idempotent\nlog.info(\"Deleted worker groups [{}] for project [{}] (idempotent).\", groups, project.getName());","handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    service.assignWorkerGroupsToProject(loginUser, projectCode, assign, delete);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.ASSIGN_WORKER_GROUP_TO_PROJECT_ERROR) {\n        // inspect current relations, then retry idempotently\n        retryAfterDelay();\n    } else { throw e; }\n}","preventionTips":["Make delete operations idempotent (0 rows = success)","Check DB health when assignment fails unexpectedly","Serialize concurrent assign requests for the same project"],"tags":["worker-group","database","persistence"],"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-14T05:17:10.506Z"}