[go: nahoru, domu]

Skip to content

Commit

Permalink
Fix order by file_upload field (HumanSignal#751)
Browse files Browse the repository at this point in the history
* Fix order by file_upload field

* Fix ordering with file_upload test
  • Loading branch information
triklozoid committed Apr 16, 2021
1 parent 4e73df2 commit 5b99c08
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
1 change: 1 addition & 0 deletions label_studio/data_manager/managers.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ def get_fields_for_annotation(prepare_params):
# we don't need to annotate regular model fields, so we skip them
skipped_fields = [field.attname for field in Task._meta.fields]
skipped_fields.append("id")
skipped_fields.append("file_upload")
result = [f for f in result if f not in skipped_fields]
result = [f for f in result if not f.startswith("data.")]

Expand Down
11 changes: 9 additions & 2 deletions label_studio/tests/data_manager/test_ordering_filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
from tests.utils import make_task, make_annotation, make_prediction, project_id
from projects.models import Project
from data_manager.models import View
from data_import.models import FileUpload
from django.conf import settings
from django.core.files.base import ContentFile
from django.utils.timezone import now


Expand All @@ -33,6 +35,8 @@
[["tasks:-data.text"], -1, False],
[["tasks:data.data"], 0, True],
[["-tasks:data.data"], 1, True],
[["tasks:file_upload"], 0, False],
[["-tasks:file_upload"], 1, False],
],
)
@pytest.mark.django_db
Expand All @@ -58,11 +62,14 @@ def test_views_ordering(ordering, element_index, undefined, business_client, pro
else:
task_field_name = 'text'

task_id_1 = make_task({"data": {task_field_name: 1}}, project).id
file_upload1 = FileUpload.objects.create(user=project.created_by, project=project, file=ContentFile('', name='file_upload1'))

task_id_1 = make_task({"data": {task_field_name: 1}, 'file_upload': file_upload1}, project).id
make_annotation({"result": [{"1": True}]}, task_id_1)
make_prediction({"result": [{"1": True}], "score": 1}, task_id_1)

task_id_2 = make_task({"data": {task_field_name: 2}}, project).id
file_upload2 = FileUpload.objects.create(user=project.created_by, project=project, file=ContentFile('', name='file_upload2'))
task_id_2 = make_task({"data": {task_field_name: 2}, 'file_upload': file_upload2}, project).id
for _ in range(0, 2):
make_annotation({"result": [{"2": True}], "was_cancelled": True}, task_id_2)
for _ in range(0, 2):
Expand Down

0 comments on commit 5b99c08

Please sign in to comment.