{"record":{"id":"030d666258a610f4","repo":"apache/shenyu","slug":"shenyu-this-discovery-is-not-found-in-current-namespace","errorCode":null,"errorMessage":"shenyu this discovery is not found in current namespace","messagePattern":"shenyu this discovery is not found in current namespace","errorType":"exception","errorClass":"ShenyuException","httpStatus":null,"severity":"error","filePath":"shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java","lineNumber":201,"sourceCode":"            discoveryHandlerMapper.insertSelective(discoveryHandlerDO);\n        }\n        DiscoveryProcessor discoveryProcessor = discoveryProcessorHolder.chooseProcessor(discoveryConfigRegisterDTO.getDiscoveryType());\n        discoveryProcessor.createDiscovery(discoveryDO);\n        discoveryProcessor.createProxySelector(DiscoveryTransfer.INSTANCE.mapToDTO(discoveryHandlerDO), proxySelectorDTO);\n    }\n\n    @Override\n    @Transactional(rollbackFor = Exception.class)\n    public String delete(final String discoveryId, final String namespaceId) {\n        List<DiscoveryHandlerDO> discoveryHandlerDOS = discoveryHandlerMapper.selectByDiscoveryId(discoveryId);\n        if (CollectionUtils.isNotEmpty(discoveryHandlerDOS)) {\n            LOG.warn(\"shenyu this discovery has discoveryHandler can't be delete\");\n            throw new ShenyuException(\"shenyu this discovery has discoveryHandler can't be delete\");\n        }\n        DiscoveryDO discoveryDO = discoveryMapper.selectById(discoveryId);\n        if (Objects.isNull(discoveryDO) || !Objects.equals(discoveryDO.getNamespaceId(), namespaceId)) {\n            LOG.warn(\"shenyu discovery {} is not found in namespace {}\", discoveryId, namespaceId);\n            throw new ShenyuException(\"shenyu this discovery is not found in current namespace\");\n        }\n        DiscoveryProcessor discoveryProcessor = discoveryProcessorHolder.chooseProcessor(discoveryDO.getDiscoveryType());\n        discoveryProcessor.removeDiscovery(discoveryDO);\n        discoveryMapper.delete(discoveryId, namespaceId);\n        return ShenyuResultMessage.DELETE_SUCCESS;\n    }\n\n    private DiscoveryVO create(final DiscoveryDTO discoveryDTO) {\n        if (Objects.isNull(discoveryDTO)) {\n            return null;\n        }\n        Timestamp currentTime = new Timestamp(System.currentTimeMillis());\n        DiscoveryDO discoveryDO = DiscoveryDO.builder()\n                .id(discoveryDTO.getId())\n                .discoveryName(discoveryDTO.getName())\n                .pluginName(discoveryDTO.getPluginName())\n                .namespaceId(discoveryDTO.getNamespaceId())\n                .discoveryType(discoveryDTO.getType())","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/apache/shenyu/blob/567142e07261b3e615ae8850b30f4421f455cc5d/shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java#L183-L219","documentation":"Thrown by DiscoveryServiceImpl.delete when the discovery record for the given discoveryId does not exist in the database, or exists but its namespaceId does not match the namespaceId passed to the call. The admin layer enforces namespace isolation: a discovery configuration may only be removed from the namespace it belongs to.","triggerScenarios":"Calling DELETE /discovery (DiscoveryServiceImpl.delete) with a discoveryId that was already deleted, that was never created, or with a namespaceId different from the one the discovery was created under (e.g. after switching the dashboard to another namespace or passing a stale/default namespace id).","commonSituations":"Stale UI state after another operator deleted the discovery; mixing namespace ids when scripting the admin REST API; multi-namespace setups where the discovery was created in a different namespace; upgrading ShenYu versions that introduced namespace scoping to legacy data.","solutions":["Verify discoveryId exists via GET /discovery/list in the target namespace before deleting","Confirm the namespaceId query/header used matches the namespace the discovery was created in","Refresh the dashboard/re-fetch the list to clear stale ids and retry","If legacy rows lack the correct namespace_id, fix the row in the discovery table instead of retrying the delete"],"exampleFix":"// before\ndiscoveryService.delete(discoveryId, namespaceId);\n// after\nDiscoveryVO vo = discoveryService.findByDiscoveryId(discoveryId);\nif (vo != null && namespaceId.equals(vo.getNamespaceId())) {\n    discoveryService.delete(discoveryId, namespaceId);\n}","handlingStrategy":"validation","validationCode":"DiscoveryDO d = discoveryMapper.selectById(discoveryId);\nif (d == null || !namespaceId.equals(d.getNamespaceId())) {\n    throw new IllegalStateException(\"discovery \" + discoveryId + \" not in namespace \" + namespaceId);\n}","typeGuard":null,"tryCatchPattern":"try {\n    discoveryService.delete(discoveryId, namespaceId);\n} catch (ShenyuException e) {\n    if (e.getMessage().contains(\"not found in current namespace\")) {\n        LOG.warn(\"skip: discovery {} not in namespace {}\", discoveryId, namespaceId);\n    } else {\n        throw e;\n    }\n}","preventionTips":["Always fetch and confirm the discovery's namespaceId before deleting","Keep namespaceId propagation consistent in admin API scripts","Refresh lists after concurrent admin operations"],"tags":["shenyu","admin","namespace","resource-not-found"],"backgroundTag":"entity-not-found","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"}