{"record":{"id":"cc76bca973ebe54c","repo":"apache/dolphinscheduler","slug":"1401002","errorCode":"1401002","errorMessage":"You can not modify or remove this worker group, cause it has [{0}] dependent environments.","messagePattern":"You can not modify or remove this worker group, cause it has \\[(.+?)\\] dependent environments\\.","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java","lineNumber":188,"sourceCode":"        // check if the worker group has any dependent schedulers\n        List<Schedule> schedules = scheduleDao.queryScheduleByWorkerGroup(workerGroup.getName());\n\n        if (CollectionUtils.isNotEmpty(schedules)) {\n            List<String> workflowDefinitionNames = schedules.stream().limit(3)\n                    .map(schedule -> workflowDefinitionDao.queryByCode(schedule.getWorkflowDefinitionCode())\n                            .orElse(null).getName())\n                    .collect(Collectors.toList());\n            throw new ServiceException(Status.WORKER_GROUP_DEPENDENT_SCHEDULER_EXISTS, schedules.size(),\n                    JSONUtils.toJsonString(workflowDefinitionNames));\n        }\n\n        // check if the worker group has any dependent environments\n        List<EnvironmentWorkerGroupRelation> environmentWorkerGroupRelations =\n                environmentWorkerGroupRelationMapper.selectList(new QueryWrapper<EnvironmentWorkerGroupRelation>()\n                        .lambda().eq(EnvironmentWorkerGroupRelation::getWorkerGroup, workerGroup.getName()));\n\n        if (CollectionUtils.isNotEmpty(environmentWorkerGroupRelations)) {\n            throw new ServiceException(Status.WORKER_GROUP_DEPENDENT_ENVIRONMENT_EXISTS,\n                    environmentWorkerGroupRelations.size());\n        }\n    }\n\n    private void checkWorkerGroupAddrList(String workerGroupAddress) {\n        if (Strings.isNullOrEmpty(workerGroupAddress)) {\n            return;\n        }\n        Map<String, String> serverMaps = registryClient.getServerMaps(RegistryNodeType.WORKER);\n        for (String addr : workerGroupAddress.split(Constants.COMMA)) {\n            if (!serverMaps.containsKey(addr)) {\n                throw new ServiceException(Status.WORKER_ADDRESS_INVALID);\n            }\n        }\n    }\n\n    /**\n     * query worker group paging","sourceCodeStart":170,"sourceCodeEnd":206,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java#L170-L206","documentation":"Thrown by checkWorkerGroupDependencies in WorkerGroupServiceImpl when a worker group cannot be deleted because one or more environments still reference it (rows exist in the environment-worker-group relation table). DolphinScheduler refuses the delete to avoid leaving environments pointing at a nonexistent worker group. The message includes the count of dependent environments.","triggerScenarios":"Calling DELETE /worker-groups/{id} (deleteWorkerGroupById) when environmentWorkerGroupRelationMapper.selectList on workerGroup.getName() returns a non-empty list, i.e. at least one environment declares this worker group name.","commonSituations":"Admin tries to remove a worker group that was selected when configuring one or more environments in the Security > Environment management page; leftover environments after renaming or consolidating worker groups.","solutions":["List environments bound to this worker group and edit each environment to remove the worker group from its workerGroups field.","Delete the environment-worker-group relation rows (via the Environment UI) if the environments are obsolete.","Retry the worker group deletion once no environments depend on it."],"exampleFix":"// before: delete directly and fail\nworkerGroupService.deleteWorkerGroupById(loginUser, id);\n// after: unbind environments first\nList<EnvironmentWorkerGroupRelation> rels = relationMapper.selectList(\n    new QueryWrapper<EnvironmentWorkerGroupRelation>()\n        .lambda().eq(EnvironmentWorkerGroupRelation::getWorkerGroup, name));\nif (rels.isEmpty()) {\n    workerGroupService.deleteWorkerGroupById(loginUser, id);\n}","handlingStrategy":"validation","validationCode":"List<EnvironmentWorkerGroupRelation> rels = relationMapper.selectList(\n    new QueryWrapper<EnvironmentWorkerGroupRelation>()\n        .lambda().eq(EnvironmentWorkerGroupRelation::getWorkerGroup, groupName));\nboolean deletable = rels.isEmpty();","typeGuard":null,"tryCatchPattern":"try {\n    workerGroupService.deleteWorkerGroupById(loginUser, id);\n} catch (ServiceException e) {\n    if (e.getCode() == 1401002) { /* unbind environments first */ }\n    else throw e;\n}","preventionTips":["Before deleting a worker group, list environments that reference it in the Environment management page.","Adopt an offboarding checklist: unbind environments -> confirm no running instances -> delete group.","Prefer renaming/retiring groups over hard delete when environments still need them."],"tags":["worker-group","environment","dependency-check","delete"],"backgroundTag":"invalid-state-transition","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"}