Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

refactor: migrate session.query to select API in delete conversation task (#34772)

Renzo289f091bf911
diff --git a/api/tasks/delete_conversation_task.py b/api/tasks/delete_conversation_task.py
index 9664b8ac738..0b392f60965 100644
--- a/api/tasks/delete_conversation_task.py
+++ b/api/tasks/delete_conversation_task.py
@@ -3,6 +3,7 @@ import time
import click
from celery import shared_task
+from sqlalchemy import delete
from core.db.session_factory import session_factory
from models import ConversationVariable
@@ -29,29 +30,21 @@ def delete_conversation_related_data(conversation_id: str):
with session_factory.create_session() as session:
try:
- session.query(MessageAnnotation).where(MessageAnnotation.conversation_id == conversation_id).delete(
- synchronize_session=False
- )
+ session.execute(delete(MessageAnnotation).where(MessageAnnotation.conversation_id == conversation_id))
+
+ session.execute(delete(MessageFeedback).where(MessageFeedback.conversation_id == conversation_id))
- session.query(MessageFeedback).where(MessageFeedback.conversation_id == conversation_id).delete(
- synchronize_session=False
+ session.execute(
+ delete(ToolConversationVariables).where(ToolConversationVariables.conversation_id == conversation_id)
)
- session.query(ToolConversationVariables).where(
- ToolConversationVariables.conversation_id == conversation_id
- ).delete(synchronize_session=False)
+ session.execute(delete(ToolFile).where(ToolFile.conversation_id == conversation_id))
- session.query(ToolFile).where(ToolFile.conversation_id == conversation_id).delete(synchronize_session=False)
+ session.execute(delete(ConversationVariable).where(ConversationVariable.conversation_id == conversation_id))
- session.query(ConversationVariable).where(ConversationVariable.conversation_id == conversation_id).delete(
- synchronize_session=False
- )
+ session.execute(delete(Message).where(Message.conversation_id == conversation_id))
- session.query(Message).where(Message.conversation_id == conversation_id).delete(synchronize_session=False)
-
- session.query(PinnedConversation).where(PinnedConversation.conversation_id == conversation_id).delete(
- synchronize_session=False
- )
+ session.execute(delete(PinnedConversation).where(PinnedConversation.conversation_id == conversation_id))
session.commit()