apache/shenyu · error · ShenyuAdminException

selector exist under those namespace!

Error message

selector exist under those namespace!

What it means

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.

Solutions

  1. Delete all selectors under the namespace first (via dashboard selector page or selector service delete API)
  2. Reassign/migrate the selectors to another namespace, then retry the delete
  3. Verify remaining references with a DB query: SELECT * FROM selector WHERE namespace_id IN (...); remove those rows
  4. If namespace deletion is truly desired, delete the dependent rules/selectors/plugins/metadata/app-auth entries in that order before calling delete

Example fix

// before
namespaceService.delete(Arrays.asList("ns-old")); // throws: selector exist under those namespace!
// after
selectorService.deleteByNamespace("ns-old"); // remove dependent selectors first
namespaceService.delete(Arrays.asList("ns-old"));
Defensive patterns

Strategy: validation

Validate before calling

if (selectorMapper.selectAllByNamespaceIds(namespaceIds).isEmpty()) {
    namespaceService.delete(namespaceIds);
}

Try / catch

try {
    namespaceService.delete(namespaceIds);
} catch (ShenyuAdminException e) {
    if (e.getMessage().contains("selector exist")) {
        // delete/migrate selectors first, then retry
    } else {
        throw e;
    }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Understand the failure class

Background: "Invalid state transition" errors: "status must be X, actually Y", "already rejected/charging/uninstalled", "cannot ... while running" — what they mean when a library rejects your call — this error's family across 31 libraries.

Related errors


AI-assisted analysis of apache/shenyu@567142e072 (2026-09-12). Data as JSON: /api/errors/1b60f71306598cb1. Report an issue: GitHub.

Appendix: source

Thrown at shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/NamespaceServiceImpl.java:149

                .collect(Collectors.toList()));
    }

    @Override
    public String delete(final List<String> ids) {
        if (ids.contains(Constants.DEFAULT_NAMESPACE_PRIMARY_KEY)) {
            throw new ShenyuAdminException(AdminConstants.SYS_DEFAULT_NAMESPACE_ID_DELETE);
        }
        List<String> namespaceIdList = namespaceMapper.selectByIds(ids).stream().map(NamespaceDO::getNamespaceId).collect(Collectors.toList());
        if (CollectionUtils.isEmpty(namespaceIdList)) {
            throw new ShenyuAdminException(AdminConstants.SYS_NAMESPACE_ID_NOT_EXIST);
        }
        List<RuleDO> ruleDOList = ruleMapper.selectAllByNamespaceIds(namespaceIdList);
        if (CollectionUtils.isNotEmpty(ruleDOList)) {
            throw new ShenyuAdminException("rule exist under those namespace!");
        }
        List<SelectorDO> selectorDOS = selectorMapper.selectAllByNamespaceIds(namespaceIdList);
        if (CollectionUtils.isNotEmpty(selectorDOS)) {
            throw new ShenyuAdminException("selector exist under those namespace!");
        }
        List<NamespacePluginVO> namespacePluginVOS = namespacePluginRelMapper.selectAllByNamespaceIds(namespaceIdList);
        if (CollectionUtils.isNotEmpty(namespacePluginVOS)) {
            throw new ShenyuAdminException("Plugins exist under those namespace!");
        }
        List<MetaDataDO> metaDataDOList = metaDataMapper.findAllByNamespaceIds(namespaceIdList);
        if (CollectionUtils.isNotEmpty(metaDataDOList)) {
            throw new ShenyuAdminException("metaData exist under those namespace!");
        }
        List<AppAuthDO> appPathDOList = appAuthMapper.findByNamespaceIds(namespaceIdList);
        if (CollectionUtils.isNotEmpty(appPathDOList)) {
            throw new ShenyuAdminException("appPath exist under those namespace!");
        }
        namespaceMapper.deleteByIds(ids);
        return ShenyuResultMessage.DELETE_SUCCESS;
    }

    @Override

View on GitHub (pinned to 567142e072)