mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 11:45:57 +08:00
fix:delete empty table bug (#15517)
Co-authored-by: huangzhuo <huangzhuo1@xiaomi.com>
This commit is contained in:
parent
e6a8800f66
commit
695a7400a9
@ -1,8 +1,10 @@
|
|||||||
import json
|
import json
|
||||||
|
import logging
|
||||||
import uuid
|
import uuid
|
||||||
from contextlib import contextmanager
|
from contextlib import contextmanager
|
||||||
from typing import Any
|
from typing import Any
|
||||||
|
|
||||||
|
import psycopg2.errors
|
||||||
import psycopg2.extras # type: ignore
|
import psycopg2.extras # type: ignore
|
||||||
import psycopg2.pool # type: ignore
|
import psycopg2.pool # type: ignore
|
||||||
from pydantic import BaseModel, model_validator
|
from pydantic import BaseModel, model_validator
|
||||||
@ -147,7 +149,14 @@ class PGVector(BaseVector):
|
|||||||
if not ids:
|
if not ids:
|
||||||
return
|
return
|
||||||
with self._get_cursor() as cur:
|
with self._get_cursor() as cur:
|
||||||
|
try:
|
||||||
cur.execute(f"DELETE FROM {self.table_name} WHERE id IN %s", (tuple(ids),))
|
cur.execute(f"DELETE FROM {self.table_name} WHERE id IN %s", (tuple(ids),))
|
||||||
|
except psycopg2.errors.UndefinedTable:
|
||||||
|
# table not exists
|
||||||
|
logging.warning(f"Table {self.table_name} not found, skipping delete operation.")
|
||||||
|
return
|
||||||
|
except Exception as e:
|
||||||
|
raise e
|
||||||
|
|
||||||
def delete_by_metadata_field(self, key: str, value: str) -> None:
|
def delete_by_metadata_field(self, key: str, value: str) -> None:
|
||||||
with self._get_cursor() as cur:
|
with self._get_cursor() as cur:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user