You've already forked DataMate
fix(annotation): 修复分段标注数据结构兼容性问题
- 添加分段标注合并异常时的日志记录和警告 - 增加分段标注保存时的详细状态日志 - 修复分段数据结构类型检查逻辑,支持dict和list格式统一转换 - 避免SQLAlchemy变更检测失效的原地修改问题 - 添加旧版list结构向新dict结构的数据迁移兼容处理
This commit is contained in:
@@ -1018,6 +1018,14 @@ class AnnotationEditorService:
|
|||||||
request.segment_index,
|
request.segment_index,
|
||||||
annotation_payload,
|
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:
|
else:
|
||||||
# 非分段模式:直接使用传入的 annotation
|
# 非分段模式:直接使用传入的 annotation
|
||||||
annotation_payload["task"] = ls_task_id
|
annotation_payload["task"] = ls_task_id
|
||||||
@@ -1057,6 +1065,18 @@ class AnnotationEditorService:
|
|||||||
else:
|
else:
|
||||||
raise HTTPException(status_code=400, detail="未发现标注内容,请确认无标注/不适用后再保存")
|
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 existing:
|
||||||
if request.expected_updated_at and existing.updated_at:
|
if request.expected_updated_at and existing.updated_at:
|
||||||
if existing.updated_at != request.expected_updated_at.replace(tzinfo=None):
|
if existing.updated_at != request.expected_updated_at.replace(tzinfo=None):
|
||||||
@@ -1126,7 +1146,15 @@ class AnnotationEditorService:
|
|||||||
if not base.get(SEGMENTED_KEY):
|
if not base.get(SEGMENTED_KEY):
|
||||||
base[SEGMENTED_KEY] = True
|
base[SEGMENTED_KEY] = True
|
||||||
segments = base.get(SEGMENTS_KEY)
|
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 = {}
|
segments = {}
|
||||||
base[SEGMENTS_KEY] = segments
|
base[SEGMENTS_KEY] = segments
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user