Handle optional annotation questions safely

This commit is contained in:
-LAN- 2025-11-03 12:57:40 +08:00
parent 4b1dbc916d
commit 2c238672da
No known key found for this signature in database
GPG Key ID: 6BA0D108DED011FF
5 changed files with 9 additions and 4 deletions

View File

@ -235,7 +235,7 @@ def migrate_annotation_vector_database():
if annotations:
for annotation in annotations:
document = Document(
page_content=annotation.question,
page_content=annotation.question_text,
metadata={"annotation_id": annotation.id, "app_id": app.id, "doc_id": annotation.id},
)
documents.append(document)

View File

@ -75,7 +75,7 @@ class AnnotationReplyFeature:
AppAnnotationService.add_annotation_history(
annotation.id,
app_record.id,
annotation.question,
annotation.question_text,
annotation.content,
query,
user_id,

View File

@ -1376,6 +1376,11 @@ class MessageAnnotation(Base):
created_at: Mapped[datetime] = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())
updated_at: Mapped[datetime] = mapped_column(sa.DateTime, nullable=False, server_default=func.current_timestamp())
@property
def question_text(self) -> str:
"""Return a non-null question string, falling back to the answer content."""
return self.question or self.content
@property
def account(self):
account = db.session.query(Account).where(Account.id == self.account_id).first()

View File

@ -226,7 +226,7 @@ class AppAnnotationService:
if app_annotation_setting:
update_annotation_to_index_task.delay(
annotation.id,
annotation.question,
annotation.question_text,
current_tenant_id,
app_id,
app_annotation_setting.collection_binding_id,

View File

@ -98,7 +98,7 @@ def enable_annotation_reply_task(
if annotations:
for annotation in annotations:
document = Document(
page_content=annotation.question,
page_content=annotation.question_text,
metadata={"annotation_id": annotation.id, "app_id": app_id, "doc_id": annotation.id},
)
documents.append(document)