apache / apache/shenyu

[BUG] Updating an API with an empty tag list leaves old tag relations

Open
#6,518 2 comments 0 reactions 1 assignee Claimed by @yykaue View on GitHub
Dominant language
Java
Stars
8.8k
Forks
3.1k
Avg merge
7d 1h
Merged PRs (30d)
85

Description

### Search before asking

- [x] I had searched in the [issues](https://github.com/apache/shenyu/issues) and found no similar issues.

### Apache ShenYu Component

shenyu-admin

### What happened

`ApiServiceImpl.update(...)` only refreshes tag relations when `apiDTO.getTagIds()` is not empty:

```java
if (updateRows > 0) {
if (CollectionUtils.isNotEmpty(apiDTO.getTagIds())) {
List tagIds = apiDTO.getTagIds();
...
tagRelationMapper.deleteByApiId(apiDO.getId());
tagRelationMapper.batchInsert(tags);
}
}
```

This means an API that already has tags cannot be updated to have no tags. If the update request sends `tagIds: []`, the condition is false, so `deleteByApiId(...)` is skipped and the old `tag_relation` rows remain in the database.

The API update succeeds, but later queries/filtering still see the previous tags.

### Expected behavior

An explicit empty tag list should clear existing API tag relations. If `null` is intended to mean "do not change tags", it should be handled separately from an empty list. The current logic treats both `null` and `[]` as "leave old tags untouched".

### How to reproduce

1. Create an API and associate one or more tags.
2. Update the same API with `tagIds` set to an empty list:

```json
{
"id": "",
"tagIds": []
}
```

3. The update returns success.
4. Query the API or inspect `tag_relation` rows for that API.
5. The old tag relations are still present because `deleteByApiId(...)` only runs when `tagIds` is non-empty.

### Debug logs

_No response_

### Environment

Current `master` branch.

### Are you willing to submit a PR?

- [ ] Yes I am willing to submit a PR!

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.