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.

When disabling the "Annotation Reply" button, the backend reports an error. #2904 (#2933)

colvin777c60749678b33
diff --git a/api/tasks/annotation/disable_annotation_reply_task.py b/api/tasks/annotation/disable_annotation_reply_task.py
index 7b88d7ac50e..e5e03c9b517 100644
--- a/api/tasks/annotation/disable_annotation_reply_task.py
+++ b/api/tasks/annotation/disable_annotation_reply_task.py
@@ -9,7 +9,7 @@ from core.rag.datasource.vdb.vector_factory import Vector
from extensions.ext_database import db
from extensions.ext_redis import redis_client
from models.dataset import Dataset
-from models.model import App, AppAnnotationSetting
+from models.model import App, AppAnnotationSetting, MessageAnnotation
@shared_task(queue='dataset')
@@ -25,7 +25,7 @@ def disable_annotation_reply_task(job_id: str, app_id: str, tenant_id: str):
App.tenant_id == tenant_id,
App.status == 'normal'
).first()
-
+ annotations_count = db.session.query(MessageAnnotation).filter(MessageAnnotation.app_id == app_id).count()
if not app:
raise NotFound("App not found")
@@ -49,8 +49,9 @@ def disable_annotation_reply_task(job_id: str, app_id: str, tenant_id: str):
)
try:
- vector = Vector(dataset, attributes=['doc_id', 'annotation_id', 'app_id'])
- vector.delete_by_metadata_field('app_id', app_id)
+ if annotations_count > 0:
+ vector = Vector(dataset, attributes=['doc_id', 'annotation_id', 'app_id'])
+ vector.delete_by_metadata_field('app_id', app_id)
except Exception:
logging.exception("Delete annotation index failed when annotation deleted.")
redis_client.setex(disable_app_annotation_job_key, 600, 'completed')