From 41d97afbefca81f93bcb4189728fd9022e886a93 Mon Sep 17 00:00:00 2001 From: shaohuzhang1 Date: Tue, 9 Dec 2025 17:07:12 +0800 Subject: [PATCH] fix: [Application] When an application with form collection is embedded into the parent application, the conversation will report an error --- apps/application/serializers/common.py | 28 +++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/apps/application/serializers/common.py b/apps/application/serializers/common.py index 5c60512add5..b7ac4c5e411 100644 --- a/apps/application/serializers/common.py +++ b/apps/application/serializers/common.py @@ -224,7 +224,33 @@ def append_chat_record(self, chat_record: ChatRecord): else: QuerySet(Chat).filter(id=self.chat_id).update(update_time=timezone.now()) # 插入会话记录 - chat_record.save() + QuerySet(ChatRecord).update_or_create(id=chat_record.id, + create_defaults={'id': chat_record.id, + 'chat_id': chat_record.chat_id, + "vote_status": chat_record.vote_status, + 'problem_text': chat_record.problem_text, + 'answer_text': chat_record.answer_text, + 'answer_text_list': chat_record.answer_text_list, + 'message_tokens': chat_record.message_tokens, + 'answer_tokens': chat_record.answer_tokens, + 'const': chat_record.const, + 'details': chat_record.details, + 'improve_paragraph_id_list': chat_record.improve_paragraph_id_list, + 'run_time': chat_record.run_time, + 'index': chat_record.index}, + defaults={ + "vote_status": chat_record.vote_status, + 'problem_text': chat_record.problem_text, + 'answer_text': chat_record.answer_text, + 'answer_text_list': chat_record.answer_text_list, + 'message_tokens': chat_record.message_tokens, + 'answer_tokens': chat_record.answer_tokens, + 'const': chat_record.const, + 'details': chat_record.details, + 'improve_paragraph_id_list': chat_record.improve_paragraph_id_list, + 'run_time': chat_record.run_time, + 'index': chat_record.index + }) ChatCountSerializer(data={'chat_id': self.chat_id}).update_chat() def to_dict(self):