alibaba/spring-ai-alibaba · error · RuntimeException

更新评估器失败

Error message

更新评估器失败

What it means

EvaluatorServiceImpl.update() calls evaluatorMapper.update(evaluatorDO) and throws RuntimeException("更新评估器失败") ("failed to update evaluator") when the affected-row count is <= 0. The UPDATE matched no rows, meaning no evaluator exists with request.getId() (or the row was changed concurrently so the WHERE clause no longer matches).

Source

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

    @Override
    public Evaluator update(EvaluatorUpdateRequest request) {
        log.info("更新评估器: {}", request);

        // 构建DO对象
        EvaluatorDO evaluatorDO = EvaluatorDO.builder()
                .id(request.getId())
                .name(request.getName())
                .description(request.getDescription())
                .build();

        // 更新数据库
        int result = evaluatorMapper.update(evaluatorDO);
        if (result > 0) {
            log.info("评估器更新成功: {}", request.getId());
            // 重新查询获取最新数据
            return Evaluator.fromDO(evaluatorMapper.selectById(request.getId()));
        } else {
            throw new RuntimeException("更新评估器失败");
        }
    }

    @Override
    public void deleteById(Long id) {
        log.info("删除评估器: {}", id);

        int result = evaluatorMapper.deleteById(id);
        if (result > 0) {
            log.info("评估器删除成功: {}", id);
        } else {
            throw new RuntimeException("删除评估器失败");
        }
    }

    @Override
    public EvaluatorDebugResult debug(EvaluatorTestRequest request) {
        log.info("调试评估器: {}", request);

View on GitHub (pinned to f82da0b50f)

Solutions

  1. Confirm the evaluator exists: call getById/selectById(request.getId()) before updating.
  2. Refresh the evaluator list and retry with a valid id.
  3. If optimistic locking is in play, re-read the current row, reapply changes, and retry.

Example fix

// before
request.setId(deletedEvaluatorId);
service.update(request); // RuntimeException
// after
if (service.getById(request.getId()) == null) {
    throw new EvaluatorNotFoundException(request.getId());
}
service.update(request);
Defensive patterns

Strategy: validation

Validate before calling

if (service.getById(request.getId()) == null) {
    throw new EvaluatorNotFoundException(request.getId());
}

Type guard

boolean evaluatorExists(Long id) { return id != null && service.getById(id) != null; }

Try / catch

try {
    return service.update(request);
} catch (RuntimeException e) {
    throw new ResponseStatusException(HttpStatus.NOT_FOUND,
        "Evaluator " + request.getId() + " no longer exists; refresh and retry");
}

Prevention

When it happens

Trigger: Updating an evaluator with an id that was never created or already deleted; a concurrent delete removed the row between load and update; an update SQL with optimistic-lock/version column that mismatches.

Common situations: Editing an evaluator in a UI tab left open while another user deleted it; stale IDs after switching environments; PUT requests replayed after the evaluator was removed.

Related errors


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