From f3b7d55a1e4f2fa2748979caaef42f93651d41c8 Mon Sep 17 00:00:00 2001 From: euvre <93761161+euvre@users.noreply.github.com> Date: Mon, 27 Apr 2026 03:52:22 +0000 Subject: [PATCH] fix: handle Infinity table-not-exist error (3022) in update() methods (#14153) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ### 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 --- api/apps/document_app.py | 19 ++++++++++++------- memory/utils/infinity_conn.py | 9 ++++++++- rag/utils/infinity_conn.py | 9 ++++++++- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/api/apps/document_app.py b/api/apps/document_app.py index 501b69068..642ff8b45 100644 --- a/api/apps/document_app.py +++ b/api/apps/document_app.py @@ -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} diff --git a/memory/utils/infinity_conn.py b/memory/utils/infinity_conn.py index 93402fa1a..ae350c0c8 100644 --- a/memory/utils/infinity_conn.py +++ b/memory/utils/infinity_conn.py @@ -440,7 +440,14 @@ class InfinityConnection(InfinityConnectionBase): try: db_instance = inf_conn.get_database(self.dbName) table_name = f"{index_name}_{memory_id}" - table_instance = db_instance.get_table(table_name) + try: + table_instance = db_instance.get_table(table_name) + except InfinityException as e: + # src/common/status.cppm, kTableNotExist = 3022 + if e.error_code == ErrorCode.TABLE_NOT_EXIST: + self.logger.warning(f"Table {table_name} does not exist, skipping update.") + return False + raise columns = {} if table_instance: diff --git a/rag/utils/infinity_conn.py b/rag/utils/infinity_conn.py index d68cd8800..45290c520 100644 --- a/rag/utils/infinity_conn.py +++ b/rag/utils/infinity_conn.py @@ -485,7 +485,14 @@ class InfinityConnection(InfinityConnectionBase): table_name = index_name else: table_name = f"{index_name}_{knowledgebase_id}" - table_instance = db_instance.get_table(table_name) + try: + table_instance = db_instance.get_table(table_name) + except InfinityException as e: + # src/common/status.cppm, kTableNotExist = 3022 + if e.error_code == ErrorCode.TABLE_NOT_EXIST: + self.logger.warning(f"Table {table_name} does not exist, skipping update.") + return False + raise # if "exists" in condition: # del condition["exists"]