Commit 8b27a81
chengjie
修复 /documents API 序列化问题:正确解析 (doc_id, DocProcessingStatus) 元组
**问题**:
- 前端报错:Cannot read properties of undefined (reading 'status')
- 根因:API 返回 `{"raw_data": "(doc_id, DocProcessingStatus(...))"}`,而不是正确的 JSON 对象
**根因分析**:
1. LightRAG 的 `get_docs_paginated()` 返回元组列表:`[(doc_id, DocProcessingStatus), ...]`
2. 当前代码未正确解包元组,触发降级处理:`{"raw_data": str(doc)}`
3. 前端无法解析 raw_data 字符串,导致 undefined 错误
**修复方案**:
- 检测元组格式:`isinstance(doc, tuple) and len(doc) == 2`
- 解包元组:`doc_id, status_obj = doc`
- 转换 DocProcessingStatus 为字典(优先使用 `asdict()` for dataclass)
- 添加 doc_id 字段
- 保留向后兼容的降级处理
**测试计划**:
- 调用远程 /documents API,验证返回格式正确
- 确认前端能正确渲染文档列表(content_summary、status、file_path 等字段)
**关联**:
- 前端团队报告的 BUG:文档列表页面空白
- 涉及文件:api/documents.py (lines 259-289)1 parent 0b6a6b0 commit 8b27a81
1 file changed
Lines changed: 22 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
258 | 259 | | |
259 | 260 | | |
260 | 261 | | |
261 | | - | |
262 | | - | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
263 | 282 | | |
264 | 283 | | |
265 | 284 | | |
266 | 285 | | |
267 | | - | |
| 286 | + | |
268 | 287 | | |
269 | 288 | | |
270 | 289 | | |
| |||
0 commit comments