Skip to content

Commit

Permalink
Fix completed job count reporting (#6106)
Browse files Browse the repository at this point in the history
- Fixed completed task job count reporting in the task summary
- Added a test

Fixes #6098
Fixes #6034
  • Loading branch information
zhiltsov-max authored May 5, 2023
1 parent 8f033b3 commit 255f2d0
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
(<https://github.com/opencv/cvat/pull/6073>)
- The issue azure.core.exceptions.ResourceExistsError: The specified blob already exists (<https://github.com/opencv/cvat/pull/6082>)
- Image scaling when moving between images with different resolution (<https://github.com/opencv/cvat/pull/6081>)
- Invalid completed job count reporting (<https://github.com/opencv/cvat/issues/6098>)

### Security
- TDB
Expand Down
6 changes: 3 additions & 3 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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),
Expand Down
20 changes: 20 additions & 0 deletions tests/python/rest_api/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 255f2d0

Please sign in to comment.