fix: handle Infinity table-not-exist error (3022) in update() methods (#14153)

### What problem does this PR solve?

## Summary

Closes #6102

When using Infinity as the document store engine (GPU version), calling
`update()` on a non-existent table throws an unhandled
`InfinityException` with error code 3022 (`TABLE_NOT_EXIST`). This
causes users to see a raw "3022" error when clicking on a parsed
document.

## Root Cause

The `update()` methods in both `rag/utils/infinity_conn.py` and
`memory/utils/infinity_conn.py` call `db_instance.get_table(table_name)`
without catching `InfinityException`. In contrast, other CRUD methods
(`insert`, `delete`, `search`) all handle this exception gracefully:

| Method   | Handles table-not-exist? | Behavior |
|----------|--------------------------|----------|
| `insert`  |  Yes | Auto-creates the table |
| `search`  |  Yes | Skips the table |
| `delete`  |  Yes | Returns 0 |
| `update`  |  **No** | Crashes with 3022 |

Additionally, `api/apps/document_app.py` worked around this with a
fragile string match (`"3022" in msg`) to detect the error.

## Changes

- **`rag/utils/infinity_conn.py`**: Catch `InfinityException` in
`update()`. When `TABLE_NOT_EXIST` is detected, log a warning and return
`False` — consistent with `delete()`.
- **`memory/utils/infinity_conn.py`**: Apply the same fix to its
`update()` method.
- **`api/apps/document_app.py`**: Remove the fragile `"3022"`
string-matching workaround. Table-not-exist is now handled by the `if
not ok` path with an improved error message.

### Type of change

- [x] Refactoring

---------

Signed-off-by: noob <yixiao121314@outlook.com>
This commit is contained in:
euvre
2026-04-27 03:52:22 +00:00
committed by GitHub
parent 33bb464ce3
commit f3b7d55a1e
3 changed files with 28 additions and 9 deletions

View File

@ -13,6 +13,7 @@
# See the License for the specific language governing permissions and
# limitations under the License
#
import logging
import os.path
import re
from pathlib import PurePosixPath, PureWindowsPath
@ -125,16 +126,20 @@ async def change_status():
search.index_name(kb.tenant_id),
doc.kb_id,
)
except Exception as exc:
msg = str(exc)
if "3022" in msg:
result[doc_id] = {"error": "Document store table missing."}
else:
result[doc_id] = {"error": f"Document store update failed: {msg}"}
except Exception:
logging.exception(
"Document store update failed in change_status: doc_id=%s kb_id=%s status=%s",
doc_id, doc.kb_id, status_int,
)
result[doc_id] = {"error": "Document store update failed."}
has_error = True
continue
if not ok:
result[doc_id] = {"error": "Database error (docStore update)!"}
logging.warning(
"Document store update returned False in change_status: doc_id=%s kb_id=%s status=%s",
doc_id, doc.kb_id, status_int,
)
result[doc_id] = {"error": "Document store table missing or update failed."}
has_error = True
continue
result[doc_id] = {"status": status}