{"record":{"id":"1b57314810e5d38c","repo":"apache/dolphinscheduler","slug":"10135","errorCode":"10135","errorMessage":"name {0} already exists","messagePattern":"name (.+?) already exists","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java","lineNumber":151,"sourceCode":"                workerGroup.setUpdateTime(now);\n                workerGroup.setDescription(description);\n                workerGroupDao.insert(workerGroup);\n            } else {\n                workerGroup = workerGroupDao.queryById(id);\n                if (workerGroup == null) {\n                    throw new ServiceException(Status.WORKER_GROUP_NOT_EXIST, id);\n                }\n                workerGroup.setName(name);\n                workerGroup.setAddrList(addrList);\n                workerGroup.setUpdateTime(now);\n                workerGroup.setDescription(description);\n                workerGroupDao.updateById(workerGroup);\n                log.info(\"Update worker group: {} success .\", workerGroup);\n            }\n            boardCastToMasterThatWorkerGroupChanged();\n            return workerGroup;\n        } catch (DuplicateKeyException duplicateKeyException) {\n            throw new ServiceException(Status.NAME_EXIST, name);\n        }\n    }\n\n    /**\n     * check if the worker group has any dependent tasks, schedulers or environments;\n     * throws ServiceException with the matching status if any dependency is found.\n     */\n    private void checkWorkerGroupDependencies(WorkerGroup workerGroup) {\n        // check if the worker group has any dependent tasks\n        List<TaskDefinition> taskDefinitions = taskDefinitionDao.queryByWorkerGroup(workerGroup.getName());\n\n        if (CollectionUtils.isNotEmpty(taskDefinitions)) {\n            List<String> taskNames = taskDefinitions.stream().limit(3).map(TaskDefinition::getName)\n                    .collect(Collectors.toList());\n            throw new ServiceException(Status.WORKER_GROUP_DEPENDENT_TASK_EXISTS, taskDefinitions.size(),\n                    JSONUtils.toJsonString(taskNames));\n        }\n","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java#L133-L169","documentation":"Status.NAME_EXIST (10135) is thrown when the worker group name collides with an existing row — saveWorkerGroup catches Spring's DuplicateKeyException from the insert/update (unique key on worker-group name) and rethrows it as a friendly 'name already exists' error.","triggerScenarios":"Creating a worker group with a name that already exists (insert duplicate key), or renaming a group to a name used by another group (update duplicate key).","commonSituations":"Two admins creating the same group concurrently; re-running a provisioning script without idempotency; case/whitespace differences that normalize to the same name in the DB unique index.","solutions":["Choose a different, unique name for the worker group.","Check existing groups first (queryByName / list API) and update the existing group instead of creating a duplicate.","Make scripts idempotent: look up by name, update if present, create only if absent.","Trim/case-normalize names before comparison to avoid near-duplicates."],"exampleFix":"// before\nworkerGroupService.saveWorkerGroup(loginUser, 0, \"default\", \"ip:1234\", \"\"); // exists\n// after\nWorkerGroup g = workerGroupService.queryByName(loginUser, \"default\");\nworkerGroupService.saveWorkerGroup(loginUser, g == null ? 0 : g.getId(), \"default\", \"ip:1234\", \"\");","handlingStrategy":"try-catch","validationCode":"boolean exists = workerGroupService.queryByName(loginUser, name) != null;\nif (exists) { /* update instead of create, or pick another name */ }","typeGuard":null,"tryCatchPattern":"try {\n    workerGroupService.saveWorkerGroup(loginUser, id, name, addrList, desc);\n} catch (ServiceException e) {\n    if (e.getCode() == 10135) { /* name collision: rename or update existing */ }\n}","preventionTips":["Check for existing names before creating","Make provisioning scripts idempotent (lookup-then-update)","Use distinct, environment-prefixed group names","Avoid near-duplicate names differing only by case/whitespace"],"tags":["worker-group","duplicate","api"],"backgroundTag":"file-already-exists","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"}