Aias00 opened a new issue, #7469: URL: https://github.com/apache/shenyu/issues/7469
## Description Namespace config import can insert a `discovery_rel` row whose selector/proxy selector reference was not remapped into the target namespace. The path is reachable through `POST /configs/import` (`shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java:131`). The discovery ZIP item is handled by `DiscoveryDataConfigsExportImportHandler.configsImport()`, which passes the parsed discovery list to `discoveryService.importData(namespaceId, discoveryList, context)` (`shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryDataConfigsExportImportHandler.java:59-61`). `DiscoveryServiceImpl.importData()` imports the discovery handler and records a handler id mapping (`shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java:516-526`). It then imports `discoveryRel` unconditionally. For relation targets, it calls `context.getSelectorIdMapping().get(selectorId)` and `context.getProxySelectorIdMapping().get(proxySelectorId)` (`DiscoveryServiceImpl.java:535-538`). If either mapping is missing, the field is set to null and the relation is still inserted at `DiscoveryServiceImpl.java:539-540`. The mapper allows this to persist. `discovery-rel-sqlmap.xml` uses `insertSelective`, so null `selector_id` and null `proxy_selector_id` columns are omitted rather than rejected (`shenyu-admin/src/main/resources/mappers/discovery-rel-sqlmap.xml:86-130`). The MySQL schema also makes both relation-target columns nullable (`db/init/mysql/schema.sql:2488-2498`). Later sync/list paths need a valid target relation. `DiscoveryHandlerMapper.selectAllByNamespaceId()` only returns handlers whose relation points to a target-namespace selector or proxy selector (`shenyu-admin/src/main/resources/mappers/discovery-handler-sqlmap.xml:72-80`). `DiscoveryUpstreamServiceImpl.buildSyncData()` then falls back to `proxySelectorId` when `selectorId` is blank and skips the handler when that proxy selector cannot be found (`shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java:196-230`). ## Trigger Import a `discovery.json` entry whose `discoveryRel.selectorId` or `discoveryRel.proxySelectorId` has no mapping in `ConfigsImportContext`. This can happen when the referenced selector/proxy selector is absent from the archive or was skipped because it already existed in the target namespace. ## Expected behavior Discovery import should require exactly one successfully remapped target: either a selector id or a proxy selector id. If the mapping is missing, it should report the discovery as failed and avoid inserting the discovery, handler, relation, and upstream rows for that tuple, or roll them back together. ## Actual behavior The importer converts missing mappings to null and still inserts the relation. The inserted relation can have neither `selector_id` nor `proxy_selector_id` pointing to a target row. ## Impact The import can report success for a discovery that is not usable by sync/list logic. Imported discovery handlers and upstreams can remain in the database but never reach the gateway, because namespace sync cannot resolve the relation to a selector or proxy selector in the target namespace. ## Suggested fix Validate the remapped relation before insertion: - require exactly one non-blank remapped `selectorId` or `proxySelectorId`; - if the mapping is missing, append a row-level import failure and skip the entire discovery tuple; - make handler/relation/upstream insertion transactional for the tuple so partial discovery topology is not persisted; - consider adding a database constraint or mapper-level guard to prevent `discovery_rel` rows with neither target column populated. ## Related existing issues This is distinct from #6695, which covers discovery upstream import writing a null `discoveryHandlerId`, and from #6465, which covers discovery upstream duplicate checks before handler-id remapping. It is also distinct from #6699, which fixed list/sync null handling after bad relation rows already exist, and from PR #7389, which copies `namespaceId` in `DiscoveryTransfer.mapToDTO`. ## Reviewed Revision And Validation Apache ShenYu 2.7.2-SNAPSHOT, master at a89b6a2338c24e978428b731e8f1edce86022418. Severity: medium. Confidence: high. Independent actual-service test reproduced null remapped relation fields; current service/DTO sources were compiled into scratch before running. Current source references: - `shenyu-admin/src/main/java/org/apache/shenyu/admin/controller/ConfigsExportImportController.java:131` - `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/configs/DiscoveryDataConfigsExportImportHandler.java:59` - `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java:516` - `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java:529` - `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryServiceImpl.java:535` - `shenyu-admin/src/main/resources/mappers/discovery-rel-sqlmap.xml:86` - `shenyu-admin/src/main/java/org/apache/shenyu/admin/service/impl/DiscoveryUpstreamServiceImpl.java:196` - `shenyu-admin/src/main/resources/mappers/discovery-handler-sqlmap.xml:72` No implementation fix or full deployed end-to-end validation was performed by this review. Source-flow and runtime evidence are distinguished above. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
