alibaba/spring-ai-alibaba · error

尝试更新不存在的数据项

Error message

尝试更新不存在的数据项: {}

What it means

DatasetItemServiceImpl.update checks whether the dataset item exists before updating. If it does not exist, it only logs '尝试更新不存在的数据项' (updating non-existent item) as a warning and then proceeds to call datasetItemMapper.update anyway — the update silently affects 0 rows and getById returns null or stale data. Unlike deleteById, it does not throw.

Solutions

  1. Fix the bug: throw after the warning (as deleteById does) or check the update's return count and throw if 0 rows affected
  2. Verify the item id exists (SELECT) before calling update from the client
  3. Check for concurrent deletes racing with updates; use optimistic locking or version columns

Example fix

// before
if(Objects.isNull(existingData)){
    log.warn("尝试更新不存在的数据项: {}", request.getId());
}
datasetItemMapper.update(request.getId(),request.getDataContent());
// after
if(Objects.isNull(existingData)){
    log.warn("尝试更新不存在的数据项: {}", request.getId());
    throw new RuntimeException("数据项不存在: " + request.getId());
}
Defensive patterns

Strategy: validation

Validate before calling

DatasetItemDO item = datasetItemMapper.selectById(id);
if (item == null) throw new RuntimeException("数据项不存在: " + id);
// only then call update

Type guard

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

Try / catch

try { service.update(req); }
catch (RuntimeException e) {
    if (e.getMessage().startsWith("数据项不存在")) { return ResponseEntity.status(404).body(e.getMessage()); }
    throw e;
}

Prevention

When it happens

Trigger: update(request) is called with a request.getId() that has no matching row in the dataset item table — already deleted, wrong id, or id from another dataset/environment.

Common situations: Client caching stale ids after a concurrent delete; UI submitting an edit for an item deleted in another tab; copy-pasted ids between dev/prod databases.

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/d73318e0a8f1a489. 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:146

    }

    @Override
    public DatasetItem getById(Long id) {
        log.info("查询数据项详情: {}", id);
        DatasetItemDO datasetItemDO = datasetItemMapper.selectById(id);
        return DatasetItem.fromDO(datasetItemDO);
    }

    @Override

    public DatasetItem update(DatasetItemUpdateRequest request) {
        log.info("更新数据项: {}", request);
        
        // 检查数据项是否存在
        DatasetItemDO existingData = datasetItemMapper.selectById(request.getId());

        if(Objects.isNull(existingData)){
            log.warn("尝试更新不存在的数据项: {}", request.getId());
        }


        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");
        }
        

View on GitHub (pinned to f82da0b50f)