fix: contact_folder_service db.refresh after commit + AI stream own DB session in generator
Check Cross-Plugin Imports / check (push) Has been cancelled
Check Cross-Plugin Imports / check (push) Has been cancelled
This commit is contained in:
@@ -578,10 +578,15 @@ async def chat_stream(
|
|||||||
}
|
}
|
||||||
|
|
||||||
async def event_stream():
|
async def event_stream():
|
||||||
async for chunk in stream_chat(
|
# Use a fresh DB session — the Depends(get_db) session closes after response
|
||||||
db, session, agent, data.content, user_context, tenant_id
|
from app.core.db import get_session_factory
|
||||||
):
|
factory = get_session_factory()
|
||||||
yield chunk
|
async with factory() as stream_db:
|
||||||
|
await set_tenant_context(stream_db, tenant_id)
|
||||||
|
async for chunk in stream_chat(
|
||||||
|
stream_db, session, agent, data.content, user_context, tenant_id
|
||||||
|
):
|
||||||
|
yield chunk
|
||||||
yield "data: [DONE]\n\n"
|
yield "data: [DONE]\n\n"
|
||||||
|
|
||||||
return StreamingResponse(
|
return StreamingResponse(
|
||||||
|
|||||||
@@ -111,9 +111,9 @@ async def create_folder(
|
|||||||
sort_order=max_order + 1,
|
sort_order=max_order + 1,
|
||||||
)
|
)
|
||||||
db.add(folder)
|
db.add(folder)
|
||||||
|
result = _serialize_folder(folder)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(folder)
|
return result
|
||||||
return _serialize_folder(folder)
|
|
||||||
|
|
||||||
|
|
||||||
async def update_folder(
|
async def update_folder(
|
||||||
@@ -143,9 +143,9 @@ async def update_folder(
|
|||||||
if "sort_order" in data and data["sort_order"] is not None:
|
if "sort_order" in data and data["sort_order"] is not None:
|
||||||
folder.sort_order = data["sort_order"]
|
folder.sort_order = data["sort_order"]
|
||||||
|
|
||||||
|
result = _serialize_folder(folder)
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(folder)
|
return result
|
||||||
return _serialize_folder(folder)
|
|
||||||
|
|
||||||
|
|
||||||
async def delete_folder(
|
async def delete_folder(
|
||||||
@@ -195,9 +195,9 @@ async def move_contact(
|
|||||||
raise ValueError("Contact not found")
|
raise ValueError("Contact not found")
|
||||||
|
|
||||||
contact.folder_id = uuid.UUID(folder_id) if folder_id else None
|
contact.folder_id = uuid.UUID(folder_id) if folder_id else None
|
||||||
|
result = {"id": str(contact.id), "folder_id": str(contact.folder_id) if contact.folder_id else None}
|
||||||
await db.commit()
|
await db.commit()
|
||||||
await db.refresh(contact)
|
return result
|
||||||
return {"id": str(contact.id), "folder_id": str(contact.folder_id) if contact.folder_id else None}
|
|
||||||
|
|
||||||
|
|
||||||
async def reorder_folders(
|
async def reorder_folders(
|
||||||
|
|||||||
Reference in New Issue
Block a user