{"record":{"id":"ed34710c522fe32f","repo":"apache/dolphinscheduler","slug":"update-environment-worker-group-relation-error","errorCode":"UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR","errorMessage":"UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR","messagePattern":"UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java","lineNumber":415,"sourceCode":"        }\n\n        Environment environment = environmentMapper.queryByEnvironmentName(environmentName);\n        if (environment != null) {\n            log.warn(\"Environment with the same name already exist, name:{}.\", environment.getName());\n            throw new ServiceException(Status.ENVIRONMENT_NAME_EXISTS, environmentName);\n        }\n    }\n\n    private void checkUsedEnvironmentWorkerGroupRelation(Set<String> deleteKeySet,\n                                                         String environmentName, Long environmentCode) {\n        for (String workerGroup : deleteKeySet) {\n            List<TaskDefinition> taskDefinitionList =\n                    taskDefinitionDao.queryByEnvironmentCodeAndWorkerGroup(environmentCode, workerGroup);\n\n            if (Objects.nonNull(taskDefinitionList) && taskDefinitionList.size() != 0) {\n                Set<String> collect =\n                        taskDefinitionList.stream().map(TaskDefinition::getName).collect(Collectors.toSet());\n                throw new ServiceException(Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR, workerGroup,\n                        environmentName, collect);\n            }\n        }\n    }\n\n    protected void checkParams(String name, String config, String workerGroups) {\n        if (StringUtils.isEmpty(name)) {\n            throw new ServiceException(Status.ENVIRONMENT_NAME_IS_NULL);\n        }\n        if (StringUtils.isEmpty(config)) {\n            throw new ServiceException(Status.ENVIRONMENT_CONFIG_IS_NULL);\n        }\n        if (StringUtils.isNotEmpty(workerGroups)) {\n            try {\n                JSONUtils.parseObject(workerGroups, new TypeReference<List<String>>() {\n                });\n            } catch (IllegalArgumentException e) {\n                throw new ServiceException(Status.ENVIRONMENT_WORKER_GROUPS_IS_INVALID);","sourceCodeStart":397,"sourceCodeEnd":433,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/EnvironmentServiceImpl.java#L397-L433","documentation":"Thrown by checkUsedEnvironmentWorkerGroupRelation when a worker group being removed from an environment is still referenced by task definitions that run under that environment+workerGroup combination. Deleting the relation would break those tasks, so the update is refused with the list of affected task names.","triggerScenarios":"updateEnvironmentByCode with workerGroups that drop one or more groups, where queryByEnvironmentCodeAndWorkerGroup finds non-empty task definitions still bound to the removed group.","commonSituations":"Removing a worker group from an environment while tasks still select that group; refactoring worker group names without migrating task definitions; cleaning up decommissioned worker groups that tasks still reference.","solutions":["Reassign the listed task definitions to another worker group first, then retry the environment update","Delete or archive the tasks that reference the removed worker group","Keep the worker group in the environment until all dependent tasks are migrated","List tasks by environment code and worker group to plan the migration"],"exampleFix":"// before\n// workerGroups: \"[\\\"groupA\\\"]\" while tasks still use groupA -> throws\n// after\n// 1) update tasks to workerGroup groupB\n// 2) then update environment with workerGroups: \"[\\\"groupB\\\"]\"","handlingStrategy":"validation","validationCode":"for (String group : groupsToRemove) {\n    List<TaskDefinition> deps = taskDefinitionDao.queryByEnvironmentCodeAndWorkerGroup(envCode, group);\n    if (deps != null && !deps.isEmpty()) {\n        throw new IllegalStateException(\"Worker group \" + group + \" still used by tasks: \"\n            + deps.stream().map(TaskDefinition::getName).collect(Collectors.toList()));\n    }\n}","typeGuard":null,"tryCatchPattern":"try {\n    environmentService.updateEnvironmentByCode(loginUser, code, name, desc, config, newWorkerGroups);\n} catch (ServiceException e) {\n    if (e.getCode() == Status.UPDATE_ENVIRONMENT_WORKER_GROUP_RELATION_ERROR.getCode()) {\n        // migrate listed tasks to another worker group, then retry\n    } else { throw e; }\n}","preventionTips":["Audit task definitions referencing a worker group before removing it from an environment","Plan worker group decommissioning with a task-migration step","Keep worker group naming consistent across environments"],"tags":["dolphinscheduler","environment","worker-group","foreign-key-constraint"],"backgroundTag":"resource-in-use","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"}