{"record":{"id":"d73318e0a8f1a489","repo":"alibaba/spring-ai-alibaba","slug":"error-d73318","errorCode":null,"errorMessage":"尝试更新不存在的数据项: {}","messagePattern":"尝试更新不存在的数据项: (.+?)","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java","lineNumber":146,"sourceCode":"    }\n\n    @Override\n    public DatasetItem getById(Long id) {\n        log.info(\"查询数据项详情: {}\", id);\n        DatasetItemDO datasetItemDO = datasetItemMapper.selectById(id);\n        return DatasetItem.fromDO(datasetItemDO);\n    }\n\n    @Override\n\n    public DatasetItem update(DatasetItemUpdateRequest request) {\n        log.info(\"更新数据项: {}\", request);\n        \n        // 检查数据项是否存在\n        DatasetItemDO existingData = datasetItemMapper.selectById(request.getId());\n\n        if(Objects.isNull(existingData)){\n            log.warn(\"尝试更新不存在的数据项: {}\", request.getId());\n        }\n\n\n        datasetItemMapper.update(request.getId(),request.getDataContent());\n\n        return getById(request.getId());\n    }\n\n    @Override\n\n    public void deleteById(Long id) {\n        log.info(\"删除数据项: {}\", id);\n        \n        // 数据验证\n        if (id == null || id <= 0) {\n            throw new IllegalArgumentException(\"数据项ID不能为空且必须大于0\");\n        }\n        ","sourceCodeStart":128,"sourceCodeEnd":164,"githubUrl":"https://github.com/alibaba/spring-ai-alibaba/blob/f82da0b50f35744c13968191be2b1cd2452ef550/spring-ai-alibaba-admin/spring-ai-alibaba-admin-server-start/src/main/java/com/alibaba/cloud/ai/studio/admin/service/impl/DatasetItemServiceImpl.java#L128-L164","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Fix the bug: throw after the warning (as deleteById does) or check the update's return count and throw if 0 rows affected","Verify the item id exists (SELECT) before calling update from the client","Check for concurrent deletes racing with updates; use optimistic locking or version columns"],"exampleFix":"// before\nif(Objects.isNull(existingData)){\n    log.warn(\"尝试更新不存在的数据项: {}\", request.getId());\n}\ndatasetItemMapper.update(request.getId(),request.getDataContent());\n// after\nif(Objects.isNull(existingData)){\n    log.warn(\"尝试更新不存在的数据项: {}\", request.getId());\n    throw new RuntimeException(\"数据项不存在: \" + request.getId());\n}","handlingStrategy":"validation","validationCode":"DatasetItemDO item = datasetItemMapper.selectById(id);\nif (item == null) throw new RuntimeException(\"数据项不存在: \" + id);\n// only then call update","typeGuard":"boolean itemExists(Long id) { return id != null && datasetItemMapper.selectById(id) != null; }","tryCatchPattern":"try { service.update(req); }\ncatch (RuntimeException e) {\n    if (e.getMessage().startsWith(\"数据项不存在\")) { return ResponseEntity.status(404).body(e.getMessage()); }\n    throw e;\n}","preventionTips":["Refresh dataset item lists after concurrent edits/deletes","Disable stale edit forms in the UI once an item is deleted","Use optimistic locking to detect concurrent modification"],"tags":["database","update","dataset","missing-check"],"backgroundTag":"record-not-found","analyzedSha":"f82da0b50f35744c13968191be2b1cd2452ef550","analyzedAt":"2026-09-09T15:32:42.421Z","contentChangedAt":"2026-09-09T15:32:42.421Z","schemaVersion":2},"datasetVersion":"2026-09-17T15:17:12.973Z"}