alibaba/spring-ai-alibaba · error

尝试删除不存在的数据项

Error message

尝试删除不存在的数据项: {}

What it means

DatasetItemServiceImpl.deleteById verifies the item exists and throws RuntimeException('数据项不存在: <id>') when it doesn't, after logging '尝试删除不存在的数据项'. This is a hard failure surfaced to the caller as an unchecked exception.

Solutions

  1. Handle or avoid the duplicate delete: make the client tolerate 'not found' (idempotent delete) or check existence first
  2. Refresh the frontend list after deletes so stale ids are not resubmitted
  3. Catch the RuntimeException in the controller and map it to a 404 response
  4. Verify the id against the correct database/environment

Example fix

// before
service.deleteById(itemId); // throws on second call
// after
try { service.deleteById(itemId); }
catch (RuntimeException e) {
    if (e.getMessage().startsWith("数据项不存在")) { /* already deleted, ok */ }
    else throw e;
}
Defensive patterns

Strategy: try-catch

Validate before calling

DatasetItemDO item = datasetItemMapper.selectById(id);
if (item == null) { /* skip delete or warn: already gone */ }

Type guard

boolean itemExists(Long id) { return id != null && id > 0 && datasetItemMapper.selectById(id) != null; }

Try / catch

try { service.deleteById(id); }
catch (RuntimeException e) {
    if (e.getMessage().startsWith("数据项不存在")) { log.info("item {} already deleted", id); }
    else throw e;
}

Prevention

When it happens

Trigger: deleteById(id) with a positive, non-null id that has no row in the dataset item table — item already deleted, wrong id, or cross-environment id.

Common situations: Double-delete from retries or UI double-click; stale list data in the frontend; deleting by id from another dataset.

Understand the failure class

Background: Record Not Found Errors: "not found", RecordNotFound, and "was not found" — what they mean and how to fix them — this error's family across 28 libraries.

Related errors


AI-assisted analysis of alibaba/spring-ai-alibaba@f82da0b50f (2026-09-09). Data as JSON: /api/errors/ae1745604540fa92. Report an issue: GitHub.

Appendix: source

Thrown at spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java:168

        datasetItemMapper.update(request.getId(),request.getDataContent());

        return getById(request.getId());
    }

    @Override

    public void deleteById(Long id) {
        log.info("删除数据项: {}", id);
        
        // 数据验证
        if (id == null || id <= 0) {
            throw new IllegalArgumentException("数据项ID不能为空且必须大于0");
        }
        
        // 检查数据项是否存在
        DatasetItemDO existingItem = datasetItemMapper.selectById(id);
        if (existingItem == null) {
            log.warn("尝试删除不存在的数据项: {}", id);
            throw new RuntimeException("数据项不存在: " + id);
        }
        

        int result = datasetItemMapper.deleteById(id);
        if (result <= 0) {
            log.error("数据项删除失败: {}", id);
            throw new RuntimeException("数据项删除失败: " + id);
        }
        
        log.info("数据项删除成功: {}", id);
    }

    @Override
    public void batchDelete(List<Long> ids) {
        log.info("批量删除数据项: {}", JSONObject.toJSONString(ids));

        datasetItemMapper.batchDeleteByIds(ids);

View on GitHub (pinned to f82da0b50f)