M4: bug report - search uuid→file_uuid column rename
This commit is contained in:
64
docs_v1.0/M4_workspace/2026-05-08_bug_search_uuid_column.md
Normal file
64
docs_v1.0/M4_workspace/2026-05-08_bug_search_uuid_column.md
Normal file
@@ -0,0 +1,64 @@
|
||||
# Bug: Search 查詢使用已更名欄位 `uuid`
|
||||
|
||||
## 發現時間
|
||||
|
||||
2026-05-08 00:50 (release 前驗證)
|
||||
|
||||
## 症狀
|
||||
|
||||
所有 search mode(bm25 / vector / hybrid)回傳 0 筆結果。
|
||||
|
||||
```bash
|
||||
curl -X POST /api/v1/search/universal \
|
||||
-d '{"query":"Audrey","uuid":"3abeee81d94597629ed8cb943f182e94","mode":"bm25"}'
|
||||
# → {"count": 0}
|
||||
```
|
||||
|
||||
## 根因
|
||||
|
||||
Migration 025 將 `chunks` 表的 `uuid` 欄位改名為 `file_uuid`,但 `universal_search.rs` 中的 SQL query 仍使用舊欄位名稱。
|
||||
|
||||
## 受影響位置
|
||||
|
||||
`src/api/universal_search.rs` — 3 處:
|
||||
|
||||
| 行號 | 原始 SQL | 應修正為 |
|
||||
|------|---------|---------|
|
||||
| 313 | `FROM chunks WHERE uuid = '{}'` | `FROM dev.chunks WHERE file_uuid = '{}'` |
|
||||
| 463 | `AND v.uuid = '{}'` | `AND v.file_uuid = '{}'` |
|
||||
| 632 | `AND v.uuid = '{}'` | `AND v.file_uuid = '{}'` |
|
||||
|
||||
## 詳細分析
|
||||
|
||||
`search_chunks()` 使用 string interpolation 建構 SQL:
|
||||
|
||||
```rust
|
||||
// line 307-313
|
||||
let uuid = match &req.uuid {
|
||||
Some(u) => u.replace('\'', "''"),
|
||||
None => return Err(anyhow::anyhow!("uuid is required for chunk search")),
|
||||
};
|
||||
let mut sql = format!(
|
||||
"SELECT ... FROM chunks WHERE uuid = '{}'", uuid // ← 應為 file_uuid
|
||||
);
|
||||
```
|
||||
|
||||
同時也存在 **SQL injection** 風險(string interpolation 而非 parameterized query),建議一併修正。
|
||||
|
||||
## 環境
|
||||
|
||||
| 項目 | 值 |
|
||||
|------|-----|
|
||||
| dev server | port 3003 |
|
||||
| schema | dev |
|
||||
| chunks 實際欄位 | `id, file_uuid, old_chunk_id, chunk_index, chunk_type, ...` |
|
||||
| 無 `uuid` 欄位 | ✅ 已確認 |
|
||||
|
||||
## 建議修正
|
||||
|
||||
```diff
|
||||
- FROM chunks WHERE uuid = '{}'
|
||||
+ FROM dev.chunks WHERE file_uuid = $1
|
||||
```
|
||||
|
||||
同時將 string interpolation 改為 parameterized query 以防止 SQL injection。
|
||||
Reference in New Issue
Block a user