fix: Fix delete document endpoint SQLite cursor handling
- Replace context manager pattern with direct cursor assignment (SQLite cursors don't support context manager protocol) - Use conn.close() instead of db_manager.return_connection() (SQLiteManager doesn't have return_connection method) Fixes 500 error when deleting documents via REST API.
This commit is contained in:
parent
046f18949c
commit
f6320faa9c
1 changed files with 31 additions and 31 deletions
|
|
@ -717,20 +717,20 @@ async def api_delete_document(kb_name: str, filename: str):
|
|||
# Get the collection ID
|
||||
conn = db_manager.get_connection()
|
||||
try:
|
||||
with conn.cursor() as cur:
|
||||
cursor = conn.cursor()
|
||||
# Get collection ID
|
||||
cur.execute(
|
||||
cursor.execute(
|
||||
"SELECT id FROM knowledge_bases WHERE name = ?",
|
||||
(kb_name,)
|
||||
)
|
||||
result = cur.fetchone()
|
||||
result = cursor.fetchone()
|
||||
if not result:
|
||||
raise HTTPException(status_code=404, detail=f"Knowledge base '{kb_name}' not found")
|
||||
|
||||
collection_id = result[0]
|
||||
|
||||
# Delete documents with this filename
|
||||
cur.execute(
|
||||
cursor.execute(
|
||||
"""
|
||||
DELETE FROM documents
|
||||
WHERE kb_id = ? AND json_extract(metadata, '$.filename') = ?
|
||||
|
|
@ -738,7 +738,7 @@ async def api_delete_document(kb_name: str, filename: str):
|
|||
""",
|
||||
(collection_id, filename)
|
||||
)
|
||||
deleted_count = len(cur.fetchall())
|
||||
deleted_count = len(cursor.fetchall())
|
||||
conn.commit()
|
||||
|
||||
if deleted_count == 0:
|
||||
|
|
@ -752,7 +752,7 @@ async def api_delete_document(kb_name: str, filename: str):
|
|||
"kb_name": kb_name
|
||||
}
|
||||
finally:
|
||||
db_manager.return_connection(conn)
|
||||
conn.close()
|
||||
|
||||
except HTTPException:
|
||||
raise
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue