{"record":{"id":"c5990b255a33061c","repo":"apache/dolphinscheduler","slug":"1401000","errorCode":"1401000","errorMessage":"You can not modify or remove this worker group, cause it has [{0}] dependent tasks like :{1}","messagePattern":"You can not modify or remove this worker group, cause it has \\[(.+?)\\] dependent tasks like :(.+?)","errorType":"exception","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java","lineNumber":166,"sourceCode":"            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\n        // 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>()","sourceCodeStart":148,"sourceCodeEnd":184,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/WorkerGroupServiceImpl.java#L148-L184","documentation":"Status.WORKER_GROUP_DEPENDENT_TASK_EXISTS (1401000) is thrown by checkWorkerGroupDependencies (invoked from deleteWorkerGroupById and group modification paths) when task definitions still reference the worker group. The message includes the count of dependent tasks and a JSON array of up to three example task names, so deletion is blocked until those references are removed.","triggerScenarios":"Deleting (or otherwise modifying) a worker group while any t_ds_task_definition row has that worker group assigned; the check runs before deleteWorkerGroupById performs the removal.","commonSituations":"Retiring a worker group that is still the default in many task definitions; environment migrations where workflows were cloned with the old group name; forgetting that copied workflows keep the original worker group setting.","solutions":["Reassign all task definitions that use this worker group to another group (edit each workflow task, or batch-update via the API/DB).","Use the taskNames list in the message to locate at least the first three offending tasks.","Query taskDefinitionDao.queryByWorkerGroup(groupName) (or equivalent API) to enumerate all dependent tasks before deleting.","If the group is truly obsolete, delete/repoint dependent tasks first, then retry the deletion.","Consider deleting the tasks/workflows that are no longer needed."],"exampleFix":"// before\nworkerGroupService.deleteWorkerGroupById(loginUser, 5); // 3 tasks still use group 'legacy'\n// after\nList<TaskDefinition> deps = taskDefinitionDao.queryByWorkerGroup(\"legacy\");\ndeps.forEach(t -> updateTaskWorkerGroup(t.getCode(), \"default\")); // reassign first\nworkerGroupService.deleteWorkerGroupById(loginUser, 5);","handlingStrategy":"validation","validationCode":"List<TaskDefinition> deps = taskDefinitionDao.queryByWorkerGroup(groupName);\nif (!deps.isEmpty()) {\n    throw new IllegalStateException(\"reassign \" + deps.size() + \" dependent tasks before delete\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    workerGroupService.deleteWorkerGroupById(loginUser, id);\n} catch (ServiceException e) {\n    if (e.getCode() == 1401000) {\n        // parse taskNames from message, reassign those tasks, then retry\n    }\n}","preventionTips":["Run dependency checks before planned deletions","Repoint task definitions to a surviving group during migrations","Search cloned workflows for the old group name after copying","Keep a 'default' fallback group for task reassignment"],"tags":["worker-group","dependencies","deletion"],"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"}