From f6788756d30e6394b43d5135048ac74eedc09db6 Mon Sep 17 00:00:00 2001 From: Jerry Yan <792602257@qq.com> Date: Sat, 31 Jan 2026 16:45:48 +0800 Subject: [PATCH] =?UTF-8?q?fix(annotation):=20=E4=BF=AE=E5=A4=8D=E5=88=86?= =?UTF-8?q?=E6=AE=B5=E6=A0=87=E6=B3=A8=E6=95=B0=E6=8D=AE=E7=BB=93=E6=9E=84?= =?UTF-8?q?=E5=85=BC=E5=AE=B9=E6=80=A7=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 添加分段标注合并异常时的日志记录和警告 - 增加分段标注保存时的详细状态日志 - 修复分段数据结构类型检查逻辑,支持dict和list格式统一转换 - 避免SQLAlchemy变更检测失效的原地修改问题 - 添加旧版list结构向新dict结构的数据迁移兼容处理 --- .../app/module/annotation/service/editor.py | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/runtime/datamate-python/app/module/annotation/service/editor.py b/runtime/datamate-python/app/module/annotation/service/editor.py index 878c389..a5f9789 100644 --- a/runtime/datamate-python/app/module/annotation/service/editor.py +++ b/runtime/datamate-python/app/module/annotation/service/editor.py @@ -1018,6 +1018,14 @@ class AnnotationEditorService: request.segment_index, annotation_payload, ) + segment_entries = self._extract_segment_annotations(final_payload) + if str(request.segment_index) not in segment_entries: + logger.warning( + "分段标注合并异常:未找到当前段落 key,project_id=%s file_id=%s segment_index=%s", + project_id, + file_id, + request.segment_index, + ) else: # 非分段模式:直接使用传入的 annotation annotation_payload["task"] = ls_task_id @@ -1057,6 +1065,18 @@ class AnnotationEditorService: else: raise HTTPException(status_code=400, detail="未发现标注内容,请确认无标注/不适用后再保存") + if request.segment_index is not None: + segment_entries = self._extract_segment_annotations(final_payload) + logger.info( + "分段标注保存:project_id=%s file_id=%s segment_index=%s segments=%s total=%s status=%s", + project_id, + file_id, + request.segment_index, + len(segment_entries), + segment_total, + final_status, + ) + if existing: if request.expected_updated_at and existing.updated_at: if existing.updated_at != request.expected_updated_at.replace(tzinfo=None): @@ -1126,7 +1146,15 @@ class AnnotationEditorService: if not base.get(SEGMENTED_KEY): base[SEGMENTED_KEY] = True segments = base.get(SEGMENTS_KEY) - if not isinstance(segments, dict): + if isinstance(segments, dict): + # 拷贝一份,避免原地修改导致 SQLAlchemy 变更检测失效 + segments = dict(segments) + base[SEGMENTS_KEY] = segments + elif isinstance(segments, list): + # 兼容旧的 list 结构,归一化为 dict 结构 + segments = self._extract_segment_annotations(base) + base[SEGMENTS_KEY] = segments + else: segments = {} base[SEGMENTS_KEY] = segments