fix(rag-trace): 修复 Request 参数因未声明泛型导致 selectPage 类型校验阻断引发 500 报错的问题#10
Open
lcz2001 wants to merge 1 commit intonageoffer:mainfrom
Open
fix(rag-trace): 修复 Request 参数因未声明泛型导致 selectPage 类型校验阻断引发 500 报错的问题#10lcz2001 wants to merge 1 commit intonageoffer:mainfrom
lcz2001 wants to merge 1 commit intonageoffer:mainfrom
Conversation
Collaborator
|
我这里似乎不报错,咱可以再检查下是否为其他问题 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🐛 Bug 描述
在访问管理后台“日志追踪”列表接口
/api/ragent/rag/traces/runs时,服务端抛出 500 异常,错误日志如下:该错误使得前端日志追踪列表一直无法正常渲染分页数据。
🔍 根本原因 (Root Cause)
在 RagTraceQueryServiceImpl.java 第 74 行调用分页查询时:
IPage<RagTraceRunDO> pageResult = runMapper.selectPage(request, wrapper);由于入参 request 的实际类型 RagTraceRunPageRequest 只是继承了 MyBatis-Plus 的 Page 类而没有声明具体的实体泛型(即触发了 Java Generics 的裸类型 Raw Type 陷阱,被视为了 Page)。
而 BaseMapper.selectPage() 的方法签名严格要求第一个参数必须实现了 IPage,导致出现 Java 强类型环境下的泛型推断阻断,引发了运行时的未决编译异常。
🛠️ 修复方案
在 Service 层的实现逻辑中,放弃将没有实体泛型的 Request 对象直接塞给 Mapper。
改为:基于 Request 的 Current 和 Size,当场显式 new 一个让 Java 1.8 能够正确进行菱形推断(Diamond Operator)的新 Page 容器,以满足泛型强约束。
修改前的代码:
IPage<RagTraceRunDO> pageResult = runMapper.selectPage(request, wrapper);修改后的代码:
IPage<RagTraceRunDO> pageParam = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(request.getCurrent(), request.getSize());IPage<RagTraceRunDO> pageResult = runMapper.selectPage(pageParam, wrapper);此方案在避免了修改 Controller 层 Request 请求体父类引起潜在耦合风险的同时,完美满足 MyBatis-Plus BaseMapper 的强泛型校验契约,Bug 修复生效。