-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: RND-98: correct response schema for tasks.get() #6012
Changes from 7 commits
0e1dcd6
312a5ae
da492a1
15019e1
6f3294c
77b2efc
a8e443d
3795960
a82bbed
9bed4be
e31fb2b
a4da046
d3592e9
0f26d2d
fcf37ee
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,10 +6,18 @@ | |
from data_manager.models import Filter, FilterGroup, View | ||
from django.conf import settings | ||
from django.db import transaction | ||
from drf_yasg import openapi | ||
from projects.models import Project | ||
from rest_framework import serializers | ||
from tasks.models import Task | ||
from tasks.serializers import AnnotationDraftSerializer, AnnotationSerializer, PredictionSerializer, TaskSerializer | ||
from tasks.serializers import ( | ||
AnnotationDraftSerializer, | ||
AnnotationResultField, | ||
AnnotationSerializer, | ||
PredictionSerializer, | ||
TaskSerializer, | ||
) | ||
from users.models import User | ||
|
||
from label_studio.core.utils.common import round_floats | ||
|
||
|
@@ -202,11 +210,51 @@ def update(self, instance, validated_data): | |
return instance | ||
|
||
|
||
class UpdatedByDMField(serializers.SerializerMethodField): | ||
# TODO: get_updated_by implementation is weird, but we need to adhere schema to it | ||
class Meta: | ||
swagger_schema_fields = { | ||
'type': openapi.TYPE_ARRAY, | ||
'title': 'User IDs', | ||
'description': 'User IDs who updated this task', | ||
'items': {'type': openapi.TYPE_OBJECT, 'title': 'User IDs'}, | ||
} | ||
|
||
|
||
class AnnotatorsDMField(serializers.SerializerMethodField): | ||
# TODO: get_updated_by implementation is weird, but we need to adhere schema to it | ||
class Meta: | ||
swagger_schema_fields = { | ||
'type': openapi.TYPE_ARRAY, | ||
'title': 'Annotators IDs', | ||
'description': 'Annotators IDs who annotated this task', | ||
'items': {'type': openapi.TYPE_INTEGER, 'title': 'User IDs'}, | ||
} | ||
|
||
|
||
class CompletedByDMSerializerWithGenericSchema(serializers.PrimaryKeyRelatedField): | ||
# TODO: likely we need to remove full user details from GET /api/tasks/{id} as it non-secure and currently controlled by the export toggle | ||
class Meta: | ||
swagger_schema_fields = { | ||
'type': openapi.TYPE_OBJECT, | ||
'title': 'User details', | ||
'description': 'User details who completed this annotation.', | ||
} | ||
|
||
|
||
class AnnotationsDMFieldSerializer(AnnotationSerializer): | ||
completed_by = CompletedByDMSerializerWithGenericSchema(required=False, queryset=User.objects.all()) | ||
|
||
|
||
class AnnotationDraftDMFieldSerializer(AnnotationDraftSerializer): | ||
result = AnnotationResultField(required=False) | ||
|
||
|
||
class DataManagerTaskSerializer(TaskSerializer): | ||
predictions = serializers.SerializerMethodField(required=False, read_only=True) | ||
annotations = AnnotationSerializer(required=False, many=True, default=[], read_only=True) | ||
drafts = serializers.SerializerMethodField(required=False, read_only=True) | ||
annotators = serializers.SerializerMethodField(required=False, read_only=True) | ||
predictions = PredictionSerializer(required=False, many=True, default=[], read_only=True) | ||
annotations = AnnotationsDMFieldSerializer(required=False, many=True, default=[], read_only=True) | ||
drafts = AnnotationDraftDMFieldSerializer(required=False, many=True, default=[], read_only=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It will break the call of some-2024-06-19_00.20.54.mp4There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed for |
||
annotators = AnnotatorsDMField(required=False, read_only=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same problem as with |
||
|
||
inner_id = serializers.IntegerField(required=False) | ||
cancelled_annotations = serializers.IntegerField(required=False) | ||
|
@@ -222,7 +270,7 @@ class DataManagerTaskSerializer(TaskSerializer): | |
predictions_model_versions = serializers.SerializerMethodField(required=False) | ||
avg_lead_time = serializers.FloatField(required=False) | ||
draft_exists = serializers.BooleanField(required=False) | ||
updated_by = serializers.SerializerMethodField(required=False, read_only=True) | ||
updated_by = UpdatedByDMField(required=False, read_only=True) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the same problem as with get_drafts() There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure the problem does appear for this field as well? As it is just as shallow override over |
||
|
||
CHAR_LIMITS = 500 | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,8 +34,8 @@ | |
'comment_count': 0, | ||
'unresolved_comment_count': 0, | ||
'last_comment_updated_at': '2024-01-15T09:30:00Z', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe it should be like this: pls, fix There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or maybe it's better to use the full version of api/tasks response:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed |
||
'updated_by': 1, | ||
'file_upload': 1, | ||
'updated_by': [{'user_id': 1}], | ||
'file_upload': '42d46c4c-my-pic.jpeg', | ||
'comment_authors': [1], | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It might affect the calls of
LseTaskSerializer::get_annotations()
andLseTaskSerializerForAnnotators::get_annotations()
from LSEThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.