wy471x opened a new pull request, #7517: URL: https://github.com/apache/shenyu/pull/7517
[X] I have read the [Contributor Guide](https://shenyu.apache.org/community/contributor-guide) [X] I have added test cases for my changes [X] I have run `./mvnw clean install -Dmaven.javadoc.skip=true` locally ## Summary Addresses #6695. `DiscoveryUpstreamServiceImpl.importData(...)` persisted a row with a `null` `discoveryHandlerId` whenever the incoming upstream carried no handler id (and, in the namespace-aware overload, whenever the handler-id remapping resolved to `null`). Such rows are orphans that never bind to a handler, or they fail mid-import on the not-null/FK constraint. Both overloads now reject an entry that has no usable handler id, record the offending URL in the import error message, and continue, instead of inserting a broken row. ### Changes: 1. `DiscoveryUpstreamServiceImpl#importData(String namespace, List, ConfigsImportContext)` (DiscoveryUpstreamServiceImpl.java) — resolve the remapped handler id once into `targetHandlerId`; if it is null/blank, append the URL to `errorMsgBuilder` and skip the entry. The same resolved id is reused for the duplicate lookup and for `setDiscoveryHandlerId`, so a `null` mapping can no longer reach `buildDiscoveryUpstreamDO`/`insert`. 2. `DiscoveryUpstreamServiceImpl#importData(List)` (same file) — apply the same null/blank guard before the duplicate check, so the non-namespace import cannot insert an orphan upstream either. ### Test Cases: - `DiscoveryUpstreamServiceTest#testImportDataSkipsNullDiscoveryHandlerId` — non-namespace import with a `null` handler id now returns successCount 0 and never calls `insert`. - `DiscoveryUpstreamServiceTest#testImportDataWithNamespaceSkipsNullDiscoveryHandlerId` — namespace import with a `null` handler id (empty remapping) returns successCount 0 and never calls `insert`. - Existing `testImportData`, `testImportDataWithNamespaceAndContext` and `testImportDataWithNamespaceUnmappedHandlerId` still pass, confirming the valid/duplicate/unmapped-but-non-null paths are unchanged. ## Verification - `./mvnw -pl shenyu-admin -am test -Dtest=DiscoveryUpstreamServiceTest` (JDK 21): 18 tests, 0 failures. - `./mvnw -pl shenyu-admin validate` (JDK 21): BUILD SUCCESS (checkstyle). - Note: the full `shenyu-admin` suite contains pre-existing, environment-dependent failures that reproduce on a clean upstream `master` checkout (`ClusterSelectMasterServiceZookeeperImplTest` — `JsonUtils.LOG` NPE, `ZookeeperClientDiscoveryIntegrationTest` — awaiting ZK upstreams); they are unrelated to this change. Fixes #6695 -- 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]
