{"record":{"id":"9ab146a3a021e44f","repo":"apache/dolphinscheduler","slug":"delete-tenant-by-id-fail-tenants","errorCode":"DELETE_TENANT_BY_ID_FAIL_TENANTS","errorMessage":"DELETE_TENANT_BY_ID_FAIL_TENANTS: {tenantCount} tenants are using this queue, delete failed","messagePattern":"DELETE_TENANT_BY_ID_FAIL_TENANTS: (.+?) tenants are using this queue, delete failed","errorType":"error_code","errorClass":"ServiceException","httpStatus":null,"severity":"error","filePath":"dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/QueueServiceImpl.java","lineNumber":232,"sourceCode":"     * @throws Exception exception\n     */\n    @Override\n    public void deleteQueueById(User loginUser, int id) throws Exception {\n\n        if (!canOperatorPermissions(loginUser, null, AuthorizationType.TENANT, TENANT_DELETE)) {\n            throw new ServiceException(Status.USER_NO_OPERATION_PERM);\n        }\n\n        Queue queue = queueDao.queryById(id);\n        if (Objects.isNull(queue)) {\n            log.error(\"Queue does not exist\");\n            throw new ServiceException(Status.QUEUE_NOT_EXIST);\n        }\n\n        List<Tenant> tenantList = tenantDao.queryTenantListByQueueId(queue.getId());\n        if (CollectionUtils.isNotEmpty(tenantList)) {\n            log.warn(\"Delete queue failed, because there are {} tenants using it.\", tenantList.size());\n            throw new ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_TENANTS, tenantList.size());\n        }\n\n        List<User> userList = userDao.queryUserListByQueue(queue.getQueueName());\n        if (CollectionUtils.isNotEmpty(userList)) {\n            log.warn(\"Delete queue failed, because there are {} users using it.\", userList.size());\n            throw new ServiceException(Status.DELETE_QUEUE_BY_ID_FAIL_USERS, userList.size());\n        }\n\n        if (!queueDao.deleteById(id)) {\n            throw new ServiceException(Status.DELETE_QUEUE_BY_ID_ERROR);\n        }\n\n    }\n\n    /**\n     * verify queue and queueName\n     *\n     * @param queue queue","sourceCodeStart":214,"sourceCodeEnd":250,"githubUrl":"https://github.com/apache/dolphinscheduler/blob/02eac45a1b6676e639fcbfb4be2243de5771b05d/dolphinscheduler-api/src/main/java/org/apache/dolphinscheduler/api/service/impl/QueueServiceImpl.java#L214-L250","documentation":"QueueServiceImpl.deleteQueueById throws ServiceException(Status.DELETE_TENANT_BY_ID_FAIL_TENANTS, tenantCount) when tenants still reference the queue: tenantDao.queryTenantListByQueueId(queue.getId()) returns a non-empty list. The delete is a referential-integrity guard — queues in use by tenants cannot be removed. The message interpolates the number of blocking tenants.","triggerScenarios":"Calling DELETE queue/{id} while one or more rows in t_ds_tenant have queue_id equal to the target queue's id; deleting a default/production YARN queue still assigned to tenants.","commonSituations":"Cleaning up old YARN queues that are still the default for tenant(s); importing tenant data pointing at the queue; multi-tenant environments where a queue remains assigned after team offboarding.","solutions":["Reassign the tenants to another queue (update each tenant's queue) via the tenant management API/UI, then retry the delete.","List the blocking tenants (the error reports the count; query t_ds_tenant WHERE queue_id = <id>) and update them in bulk.","If the queue truly should not be referenced, migrate the tenants' queue_id in the database during a maintenance window, then delete the queue."],"exampleFix":"// before: delete while tenants still use queue\nDELETE /dolphinscheduler/queues/7 -> DELETE_TENANT_BY_ID_FAIL_TENANTS (3 tenants)\n\n// after: reassign tenants first\ntenantService.updateTenant(loginUser, tenantId, ..., newQueueId); // for each of the 3 tenants\ndeleteQueueById(loginUser, 7) -> succeeds","handlingStrategy":"validation","validationCode":"// check tenant references before deleting\nList<Tenant> tenants = tenantDao.queryTenantListByQueueId(id);\nif (!tenants.isEmpty()) {\n    throw new IllegalStateException(\"Queue \" + id + \" still used by \" + tenants.size() + \" tenant(s)\");\n}","typeGuard":null,"tryCatchPattern":"try {\n    queueService.deleteQueueById(loginUser, id);\n} catch (ServiceException e) {\n    if (Status.DELETE_TENANT_BY_ID_FAIL_TENANTS.getCode() == e.getCode()) {\n        // reassign tenants then retry\n    } else { throw e; }\n}","preventionTips":["Reassign tenants off a queue before decommissioning it","Audit t_ds_tenant.queue_id during cleanup","Document queue-to-tenant dependencies"],"tags":["queue-management","referential-integrity","tenant"],"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"}