Skip to content

Commit

Permalink
fix: OPTIC-1420: Inner IDs are duplicated and counted wrong (#6785)
Browse files Browse the repository at this point in the history
Co-authored-by: mcanu <[email protected]>
  • Loading branch information
mcanu and mcanu authored Dec 18, 2024
1 parent adeb2ed commit bd3498d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions label_studio/tasks/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from core.feature_flags import flag_set
from core.label_config import replace_task_data_undefined_with_config_field
from core.utils.common import load_func, retry_database_locked
from core.utils.db import fast_first
from django.conf import settings
from django.db import IntegrityError, transaction
from drf_yasg import openapi
Expand Down Expand Up @@ -533,10 +534,13 @@ def add_tasks(self, task_annotations, task_predictions, validated_tasks):
db_tasks = []
max_overlap = self.project.maximum_annotations

# identify max inner id
tasks = Task.objects.filter(project=self.project)
prev_inner_id = tasks.order_by('-inner_id')[0].inner_id if tasks else 0
# Acquire a lock on the project to ensure atomicity when calculating inner_id
project = Project.objects.select_for_update().get(id=self.project.id)

last_task = fast_first(Task.objects.filter(project=project).order_by('-inner_id'))
prev_inner_id = last_task.inner_id if last_task else 0
max_inner_id = (prev_inner_id + 1) if prev_inner_id else 1

for i, task in enumerate(validated_tasks):
cancelled_annotations = len([ann for ann in task_annotations[i] if ann.get('was_cancelled', False)])
total_annotations = len(task_annotations[i]) - cancelled_annotations
Expand Down

0 comments on commit bd3498d

Please sign in to comment.