diff --git a/CHANGELOG.md b/CHANGELOG.md index a31fe722f56e..5471a6882f17 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 () - The issue azure.core.exceptions.ResourceExistsError: The specified blob already exists () - Image scaling when moving between images with different resolution () +- Invalid completed job count reporting () ### Security - TDB diff --git a/cvat/apps/engine/views.py b/cvat/apps/engine/views.py index 17fda86f7840..99594b309836 100644 --- a/cvat/apps/engine/views.py +++ b/cvat/apps/engine/views.py @@ -20,7 +20,6 @@ from django.db import IntegrityError from django.http import HttpResponse, HttpResponseNotFound, HttpResponseBadRequest from django.utils import timezone -import django.db.models as dj_models from django.db.models import Count, Q from drf_spectacular.types import OpenApiTypes @@ -668,9 +667,10 @@ class TaskViewSet(viewsets.GenericViewSet, mixins.ListModelMixin, 'label_set__sublabels__attributespec_set', 'project__label_set__sublabels__attributespec_set' ).annotate( - completed_jobs_count=dj_models.Count( + completed_jobs_count=Count( 'segment__job', - filter=dj_models.Q(segment__job__state=models.StateChoice.COMPLETED.value) + filter=Q(segment__job__state=models.StateChoice.COMPLETED.value), + distinct=True ), task_labels_count=Count('label', filter=Q(label__parent__isnull=True), distinct=True), diff --git a/tests/python/rest_api/test_tasks.py b/tests/python/rest_api/test_tasks.py index 3f27ed1df3dd..2dcafc795a44 100644 --- a/tests/python/rest_api/test_tasks.py +++ b/tests/python/rest_api/test_tasks.py @@ -1498,3 +1498,23 @@ def test_user_cannot_update_task_with_cloud_storage_without_access( _check_status=False, ) assert response.status == HTTPStatus.FORBIDDEN + + +@pytest.mark.usefixtures("restore_db_per_function") +def test_can_report_correct_completed_jobs_count(tasks, jobs, admin_user): + # Reproduces https://github.com/opencv/cvat/issues/6098 + task = next( + t + for t in tasks + if t["jobs"]["count"] > 1 and t["jobs"]["completed"] == 0 and t["labels"]["count"] > 1 + ) + task_jobs = [j for j in jobs if j["task_id"] == task["id"]] + + with make_api_client(admin_user) as api_client: + api_client.jobs_api.partial_update( + task_jobs[0]["id"], + patched_job_write_request=dict(stage="acceptance", state="completed"), + ) + + task, _ = api_client.tasks_api.retrieve(task["id"]) + assert task.jobs.completed == 1