mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-06-29 15:31:05 +08:00
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:
@@ -13,6 +13,7 @@
|
|||||||
# See the License for the specific language governing permissions and
|
# See the License for the specific language governing permissions and
|
||||||
# limitations under the License
|
# limitations under the License
|
||||||
#
|
#
|
||||||
|
import logging
|
||||||
import os.path
|
import os.path
|
||||||
import re
|
import re
|
||||||
from pathlib import PurePosixPath, PureWindowsPath
|
from pathlib import PurePosixPath, PureWindowsPath
|
||||||
@@ -125,16 +126,20 @@ async def change_status():
|
|||||||
search.index_name(kb.tenant_id),
|
search.index_name(kb.tenant_id),
|
||||||
doc.kb_id,
|
doc.kb_id,
|
||||||
)
|
)
|
||||||
except Exception as exc:
|
except Exception:
|
||||||
msg = str(exc)
|
logging.exception(
|
||||||
if "3022" in msg:
|
"Document store update failed in change_status: doc_id=%s kb_id=%s status=%s",
|
||||||
result[doc_id] = {"error": "Document store table missing."}
|
doc_id, doc.kb_id, status_int,
|
||||||
else:
|
)
|
||||||
result[doc_id] = {"error": f"Document store update failed: {msg}"}
|
result[doc_id] = {"error": "Document store update failed."}
|
||||||
has_error = True
|
has_error = True
|
||||||
continue
|
continue
|
||||||
if not ok:
|
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
|
has_error = True
|
||||||
continue
|
continue
|
||||||
result[doc_id] = {"status": status}
|
result[doc_id] = {"status": status}
|
||||||
|
|||||||
@@ -440,7 +440,14 @@ class InfinityConnection(InfinityConnectionBase):
|
|||||||
try:
|
try:
|
||||||
db_instance = inf_conn.get_database(self.dbName)
|
db_instance = inf_conn.get_database(self.dbName)
|
||||||
table_name = f"{index_name}_{memory_id}"
|
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 = {}
|
columns = {}
|
||||||
if table_instance:
|
if table_instance:
|
||||||
|
|||||||
@@ -485,7 +485,14 @@ class InfinityConnection(InfinityConnectionBase):
|
|||||||
table_name = index_name
|
table_name = index_name
|
||||||
else:
|
else:
|
||||||
table_name = f"{index_name}_{knowledgebase_id}"
|
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:
|
# if "exists" in condition:
|
||||||
# del condition["exists"]
|
# del condition["exists"]
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user