Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: OPTIC-1420: Inner IDs are duplicated and counted wrong #6785

Merged
merged 4 commits into from
Dec 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading