{"record":{"id":"1b60f71306598cb1","repo":"apache/shenyu","slug":"selector-exist-under-those-namespace","errorCode":null,"errorMessage":"selector exist under those namespace!","messagePattern":"selector exist under those namespace!","errorType":"exception","errorClass":"ShenyuAdminException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java","lineNumber":149,"sourceCode":"                .collect(Collectors.toList()));\n    }\n\n    @Override\n    public String delete(final List<String> ids) {\n        if (ids.contains(Constants.DEFAULT_NAMESPACE_PRIMARY_KEY)) {\n            throw new ShenyuAdminException(AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE);\n        }\n        List<String> namespaceIdList = namespaceMapper.selectByIds(ids).stream().map(NamespaceDO::getNamespaceId).collect(Collectors.toList());\n        if (CollectionUtils.isEmpty(namespaceIdList)) {\n            throw new ShenyuAdminException(AdminConstants.SYS_NAMESPACE_ID_NOT_EXIST);\n        }\n        List<RuleDO> ruleDOList = ruleMapper.selectAllByNamespaceIds(namespaceIdList);\n        if (CollectionUtils.isNotEmpty(ruleDOList)) {\n            throw new ShenyuAdminException(\"rule exist under those namespace!\");\n        }\n        List<SelectorDO> selectorDOS = selectorMapper.selectAllByNamespaceIds(namespaceIdList);\n        if (CollectionUtils.isNotEmpty(selectorDOS)) {\n            throw new ShenyuAdminException(\"selector exist under those namespace!\");\n        }\n        List<NamespacePluginVO> namespacePluginVOS = namespacePluginRelMapper.selectAllByNamespaceIds(namespaceIdList);\n        if (CollectionUtils.isNotEmpty(namespacePluginVOS)) {\n            throw new ShenyuAdminException(\"Plugins exist under those namespace!\");\n        }\n        List<MetaDataDO> metaDataDOList = metaDataMapper.findAllByNamespaceIds(namespaceIdList);\n        if (CollectionUtils.isNotEmpty(metaDataDOList)) {\n            throw new ShenyuAdminException(\"metaData exist under those namespace!\");\n        }\n        List<AppAuthDO> appPathDOList = appAuthMapper.findByNamespaceIds(namespaceIdList);\n        if (CollectionUtils.isNotEmpty(appPathDOList)) {\n            throw new ShenyuAdminException(\"appPath exist under those namespace!\");\n        }\n        namespaceMapper.deleteByIds(ids);\n        return ShenyuResultMessage.DELETE_SUCCESS;\n    }\n\n    @Override","sourceCodeStart":131,"sourceCodeEnd":167,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java#L131-L167","documentation":"ShenYu admin refuses to delete a namespace while selectors still reference it. Deletion runs a cascade of referential-integrity checks (rules, selectors, plugins, metadata, app auth) and aborts with this ShenyuAdminException if any dependent row exists, because a namespace with selectors is still actively routing gateway traffic.","triggerScenarios":"Calling NamespaceService.delete (or the admin dashboard delete endpoint) for a namespace whose selector table contains rows with that namespaceId, i.e. namespaceIdList passed to selectorMapper.selectAllByNamespaceIds returns non-empty.","commonSituations":"Attempting to decommission or clean up a namespace that still has plugin selector configurations created via the dashboard or client auto-registration; deleting a default/production namespace without first migrating its API selectors.","solutions":["Delete all selectors under the namespace first (via dashboard selector page or selector service delete API)","Reassign/migrate the selectors to another namespace, then retry the delete","Verify remaining references with a DB query: SELECT * FROM selector WHERE namespace_id IN (...); remove those rows","If namespace deletion is truly desired, delete the dependent rules/selectors/plugins/metadata/app-auth entries in that order before calling delete"],"exampleFix":"// before\nnamespaceService.delete(Arrays.asList(\"ns-old\")); // throws: selector exist under those namespace!\n// after\nselectorService.deleteByNamespace(\"ns-old\"); // remove dependent selectors first\nnamespaceService.delete(Arrays.asList(\"ns-old\"));","handlingStrategy":"validation","validationCode":"if (selectorMapper.selectAllByNamespaceIds(namespaceIds).isEmpty()) {\n    namespaceService.delete(namespaceIds);\n}","typeGuard":null,"tryCatchPattern":"try {\n    namespaceService.delete(namespaceIds);\n} catch (ShenyuAdminException e) {\n    if (e.getMessage().contains(\"selector exist\")) {\n        // delete/migrate selectors first, then retry\n    } else {\n        throw e;\n    }\n}","preventionTips":["Before deleting a namespace, query its selectors and remove or migrate them","Track which namespaces still have live selector configuration in the dashboard","Treat namespace deletion as a terminal cleanup step, performed after all resources are drained"],"tags":["shenyu","admin","namespace","referential-integrity","dependency-conflict"],"backgroundTag":"invalid-state-transition","analyzedSha":"567142e07261b3e615ae8850b30f4421f455cc5d","analyzedAt":"2026-09-12T10:08:21.293Z","contentChangedAt":"2026-09-12T10:08:21.293Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}