Skip to content

Commit

Permalink
Fix exception when run export for an empty task (#5396)
Browse files Browse the repository at this point in the history
Fix #5245

The PR contains a simple fix. Just return BAD REQUEST if somebody tries
to export a task without data. It doesn't make sense. But a more complex
fix will require changing a massive amount of code. It doesn't make any
sense to support such a weird scenario.
  • Loading branch information
nmanovic authored Dec 1, 2022
1 parent c0bf27c commit 3e1ccc8
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ non-ascii paths while adding files from "Connected file share" (issue #4428)
- Visibility and ignored information fail to be loaded (MOT dataset format) (<https://github.com/opencv/cvat/pull/5270>)
- Added force logout on CVAT app start if token is missing (<https://github.com/opencv/cvat/pull/5331>)
- Missed token with using social account authentication (<https://github.com/opencv/cvat/pull/5344>)
- An exception when run export for an empty task (<https://github.com/opencv/cvat/pull/5396>)
- Fixed FBRS serverless function runtime error on images with alpha channel (<https://github.com/opencv/cvat/pull/5384>)
- Attaching manifest with custom name (<https://github.com/opencv/cvat/pull/5377>)
- Uploading non-zip annotaion files (<https://github.com/opencv/cvat/pull/5386>)
Expand Down
39 changes: 24 additions & 15 deletions cvat/apps/engine/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1061,6 +1061,7 @@ def append_data_chunk(self, request, pk, file_id):
), description='Download of file started'),
'201': OpenApiResponse(description='Annotations file is ready to download'),
'202': OpenApiResponse(description='Dump of annotations has been started'),
'400': OpenApiResponse(description='Exporting without data is not allowed'),
'405': OpenApiResponse(description='Format is not available'),
})
@extend_schema(methods=['PUT'], summary='Method allows to upload task annotations',
Expand Down Expand Up @@ -1120,14 +1121,18 @@ def append_data_chunk(self, request, pk, file_id):
def annotations(self, request, pk):
self._object = self.get_object() # force to call check_object_permissions
if request.method == 'GET':
return self.export_annotations(
request=request,
pk=pk,
db_obj=self._object,
export_func=_export_annotations,
callback=dm.views.export_task_annotations,
get_data=dm.task.get_task_data,
)
if self._object.data:
return self.export_annotations(
request=request,
pk=pk,
db_obj=self._object,
export_func=_export_annotations,
callback=dm.views.export_task_annotations,
get_data=dm.task.get_task_data,
)
else:
return Response(data="Exporting a task without data is not allowed",
status=status.HTTP_400_BAD_REQUEST)
elif request.method == 'POST' or request.method == 'OPTIONS':
return self.import_annotations(
request=request,
Expand Down Expand Up @@ -1290,20 +1295,24 @@ def metadata(self, request, pk):
'200': OpenApiResponse(OpenApiTypes.BINARY, description='Download of file started'),
'201': OpenApiResponse(description='Output file is ready for downloading'),
'202': OpenApiResponse(description='Exporting has been started'),
'400': OpenApiResponse(description='Exporting without data is not allowed'),
'405': OpenApiResponse(description='Format is not available'),
})
@action(detail=True, methods=['GET'], serializer_class=None,
url_path='dataset')
def dataset_export(self, request, pk):
self._object = self.get_object() # force to call check_object_permissions

return self.export_annotations(
request=request,
pk=pk,
db_obj=self._object,
export_func=_export_annotations,
callback=dm.views.export_task_as_dataset
)
if self._object.data:
return self.export_annotations(
request=request,
pk=pk,
db_obj=self._object,
export_func=_export_annotations,
callback=dm.views.export_task_as_dataset)
else:
return Response(data="Exporting a task without data is not allowed",
status=status.HTTP_400_BAD_REQUEST)

@extend_schema(tags=['jobs'])
@extend_schema_view(
Expand Down

0 comments on commit 3e1ccc8

Please sign in to comment.