harshkha3417 opened a new pull request, #7800:
URL: https://github.com/apache/shenyu/pull/7800

   Fixes #7772.
   
   ### Motivation
   
   When updating a tag in `TagServiceImpl`:
   1. `TagDO.buildTagDO(tagDTO)` creates a `TagDO` where `ext` is `null`. 
Because `tagMapper.updateByPrimaryKeySelective(tagDO)` ignores `null` fields, 
the edited tag's own `ext` in the database was never updated. When reparenting 
a tag or renaming it, its `ext` remained stale with outdated parent metadata.
   2. In `updateSubTags`, a `TagDO` with `ext == null` was put into 
`allDataMap`. When `recurseUpdateTag` updated descendant tags, 
`buildExtParamByParentTag` received `parentTagDO.getExt() == null` and fell 
back to an empty `TagExt` (`parent == null`). This caused all ancestors above 
the updated node (grandparents, root tag, etc.) to be truncated and erased from 
the descendants' ancestry.
   3. If an updated tag was reparented to a non-existent parent, the parent 
existence was not validated on update, unlike during tag creation (#6535).
   
   ### Key Changes
   
   - **Update tag `ext` correctly (`TagServiceImpl.java`)**:
     - Resolve the effective `parentTagId` (retaining existing parent if 
omitted in DTO).
     - When non-root: validate parent existence (`Assert.notNull(parentTagDO, 
"parent tag is not found")`) and build the new `ext` from the parent's ancestry 
while preserving any existing document metadata (`refreshTime`, `apiDocMd5`, 
etc.).
     - When root (`parentTagId == "0"`): clear `parent` in `TagExt` while 
preserving document metadata.
     - Set `tagDO.setExt(...)` so `updateByPrimaryKeySelective` persists the 
fresh parent/ancestor metadata to the database.
   - **Preserve descendant ancestry (`TagServiceImpl.java`)**:
     - Seed `allDataMap` with the fully populated `TagDO` (including its 
updated `ext`).
     - Pass the descendant's existing `ext` into 
`buildExtParamByParentTag(allData.get(id), tagDO.getExt())` to update its 
parent pointer without discarding the node's own metadata.
     - Recursively update the tree so all descendants retain the complete, 
unbroken ancestor chain.
   - **Tests**:
     - Added unit test cases in `TagServiceTest` for non-existent tag and 
non-existent parent validation on update.
     - Added integration test cases in `TagUpdateTransactionTest` verifying 
multi-tier ancestor preservation (`child -> parent -> root`), reparenting 
across trees, and promoting a child tag to root.


-- 
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]

Reply via email to