diff --git a/runtime/datamate-python/app/module/annotation/service/editor.py b/runtime/datamate-python/app/module/annotation/service/editor.py index 1cd5587..878c389 100644 --- a/runtime/datamate-python/app/module/annotation/service/editor.py +++ b/runtime/datamate-python/app/module/annotation/service/editor.py @@ -992,11 +992,19 @@ class AnnotationEditorService: ls_task_id = self._make_ls_task_id(project_id, file_id) + segment_total_hint = None + if request.segment_index is not None: + segment_total_hint = self._resolve_segment_total(annotation_payload) + if segment_total_hint is None: + segment_total_hint = await self._compute_segment_total(project, file_record, file_id) + existing_result = await self.db.execute( - select(AnnotationResult).where( + select(AnnotationResult) + .where( AnnotationResult.project_id == project_id, AnnotationResult.file_id == file_id, ) + .with_for_update() ) existing = existing_result.scalar_one_or_none() @@ -1026,7 +1034,7 @@ class AnnotationEditorService: if request.segment_index is not None: segment_total = self._resolve_segment_total(final_payload) if segment_total is None: - segment_total = await self._compute_segment_total(project, file_record, file_id) + segment_total = segment_total_hint if segment_total and segment_total > 0: final_payload[SEGMENT_TOTAL_KEY] = segment_total segment_done = len(self._extract_segment_annotations(final_payload))