{"record":{"id":"c1cfb41d6f9cfc10","repo":"apache/dolphinscheduler","slug":"alert-group-exist","errorCode":"ALERT_GROUP_EXIST","errorMessage":"ALERT_GROUP_EXIST","messagePattern":"ALERT_GROUP_EXIST","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java","lineNumber":173,"sourceCode":"        alertGroup.setGroupName(groupName);\n        alertGroup.setAlertInstanceIds(alertInstanceIds);\n        alertGroup.setDescription(desc);\n        alertGroup.setCreateTime(now);\n        alertGroup.setUpdateTime(now);\n        alertGroup.setCreateUserId(loginUser.getId());\n\n        // insert\n        try {\n            int insert = alertGroupDao.insert(alertGroup);\n            if (insert > 0) {\n                log.info(\"Create alert group complete, groupName:{}\", alertGroup.getGroupName());\n                return alertGroup;\n            }\n            log.error(\"Create alert group error, groupName:{}\", alertGroup.getGroupName());\n            throw new ServiceException(Status.CREATE_ALERT_GROUP_ERROR);\n        } catch (DuplicateKeyException ex) {\n            log.error(\"Create alert group error, groupName:{}\", alertGroup.getGroupName(), ex);\n            throw new ServiceException(Status.ALERT_GROUP_EXIST);\n        }\n    }\n\n    /**\n     * updateWorkflowInstance alert group\n     *\n     * @param loginUser login user\n     * @param id alert group id\n     * @param groupName group name\n     * @param desc description\n     * @param alertInstanceIds alertInstanceIds\n     * @return update result code\n     */\n    @Override\n    public AlertGroup updateAlertGroupById(User loginUser, int id, String groupName, String desc,\n                                           String alertInstanceIds) {\n        if (!canOperatorPermissions(loginUser, new Object[]{id}, AuthorizationType.ALERT_GROUP, ALERT_GROUP_UPDATE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);","sourceCodeStart":155,"sourceCodeEnd":191,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/AlertGroupServiceImpl.java#L155-L191","documentation":"DolphinScheduler throws this when creating an alert group fails because the group name already exists. The insert/update hits a unique key on the alert group name, Spring translates the database DuplicateKeyException into ServiceException(Status.ALERT_GROUP_EXIST). It prevents duplicate-named alert groups.","triggerScenarios":"Calling POST /alert-groups (AlertGroupService.createAlertGroup) with a groupName that already exists in t_ds_alert_group, causing a unique-key violation on insert.","commonSituations":"Re-running a setup script or automation that creates alert groups without checking existence; two admins creating the same group name concurrently; restoring/migrating groups that already exist in the target environment.","solutions":["Pick a different, unique groupName for the new alert group","Query existing groups first (list-alert-groups) and skip creation if the name already exists","In automation, catch the exception and treat ALERT_GROUP_EXIST as idempotent success","Verify the DB unique index on group_name is intended before bulk-importing groups"],"exampleFix":"// before\nalertGroupService.createAlertGroup(loginUser, \"ops-team\", \"oncall\", \"\");\n// after\nif (alertGroupService.queryAlertGroupByGroupName(\"ops-team\") == null) {\n    alertGroupService.createAlertGroup(loginUser, \"ops-team\", \"oncall\", \"\");\n}","handlingStrategy":"try-catch","validationCode":"List<AlertGroup> groups = alertGroupService.queryAllAlertGroup(loginUser);\nboolean exists = groups.stream().anyMatch(g -> g.getGroupName().equals(name));\nif (exists) throw new IllegalArgumentException(\"group name already in use: \" + name);","typeGuard":null,"tryCatchPattern":"try {\n    alertGroupService.createAlertGroup(loginUser, name, desc, \"\");\n} catch (ServiceException e) {\n    if (e.getCode() == Status.ALERT_GROUP_EXIST) { /* handle duplicate */ }\n    else throw e;\n}","preventionTips":["Check for an existing group with the same name before creating","Make creation scripts idempotent","Enforce unique naming conventions across teams"],"tags":["duplicate-resource","database","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"}