fix(admin): preserve omitted tag fields in descendant ancestry #8057
The preservation is correct and the asymmetry is deliberate, but it deserves a comment.
Verified:
before is null-checked by Assert.notNull (line 98), so before.getTagName() / getTagDesc() cannot NPE.java.util.Objects is already imported (line 42), and the test file already imports ObjectMapper, ParameterizedTest, ValueSource, assertNull and Objects, so both modules compile.updateSubTags propagates tagDO, descendants now carry the preserved name/description in their ancestor chain — which is exactly what assertAncestor checks. The fix and the test agree.One nit worth a line of comment:
parentTagId falls back on StringUtils.isNotEmpty (so "" falls back to the stored value), while tagName / tagDesc fall back only on Objects.isNull (so "" is written as a real value). That is intentional — {"tagDesc":""} in the parameterized test asserts an explicit clear — but the two adjacent rules read as an oversight. A short comment on why tagDesc may be cleared while parentTagId may not would keep the next reader from "fixing" it.
Not blocking.
The comment describes the parent-id rule, but it sits above the name/description assignments. Consider moving the parent half up next to setParentTagId (line 104) and keeping only "a null name/description retains the persisted value; an explicit empty string clears it" here, so each line documents the rule it implements.
Small, targeted, and verified.
Verification I ran locally
setName / setTagDesc) makes 7 of 17 cases in TagUpdateTransactionTest fail, which matches the seven partial-JSON cases the description claims; with the patch, TagUpdateTransactionTest + TagControllerTest are 24/24 green and checkstyle:check is clean on shenyu-admin.before is read from the database at the top of update, so it is the persisted row, not the incoming DTO — the fallback is against real state.parentTagId handling directly above already had exactly this shape (isNotEmpty → fall back to before), so name/description now follow the pattern that was already established in the method instead of inventing a new one.updateByPrimaryKeySelective would not have written nulls anyway; the observable damage was confined to the values updateSubTags embeds into descendant ext, which is precisely what the fix targets. Descendant refreshTime is preserved as asserted.@BeforeEach re-inserts the four rows for every parameterized invocation and @AfterEach deletes them, so the mutations cannot leak between cases.CI
The only red jobs are shenyu-integrated-test-{http,grpc,combination,rewrite,https,sdk-http}, all failing on CachePluginTest.testMemoryModle / testRedisModle. The same two cases fail identically on #8076, which touches divide only, in the same time window — that is a master-level flake, not something this PR introduces.
The preservation logic is right, and the placement is right too: it runs after TagDO.buildTagDO and before updateSubTags, so the descendants' cached ancestor name/desc are rebuilt from the same values that are written to the row. before is already guarded by Assert.notNull, and Objects was already imported, so nothing else is needed.
The parameterized test is the valuable part here — {"name":null,"tagDesc":null} and {} are the two cases that used to blank the columns, and asserting on both the row and the descendant ext is what makes it a real regression test rather than a mock check.
One thing to be aware of, not a blocker: {"name":""} still writes an empty name, because TagDTO carries no constraints and the check is isNull, not isBlank. That matches the previous behaviour for an explicit empty string, so it is not a regression, but if an empty tag name is invalid the validation belongs on the DTO rather than here.
Aias00
yangjj-iso
Fixes #8027.
Description-only, name-only and parent-only tag updates preserve omitted fields in the database but previously rebuilt descendant ancestry with null values. Merge persisted name/description before propagating the effective tag. Null retains the persisted value; an explicit empty string remains an update.
Validation on Microsoft OpenJDK 17.0.18 through mvnw.cmd:
Full repository and Docker E2E suites were not run.