From a974e4a403180c3b69610e5def310ff39e72c84a Mon Sep 17 00:00:00 2001 From: Andrey Zhavoronkov <41117609+azhavoro@users.noreply.github.com> Date: Thu, 10 Jan 2019 16:21:31 +0300 Subject: [PATCH] release db lock after _AnnotationForTask instance initialized for dump functionality (#270) --- cvat/apps/engine/annotation.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/cvat/apps/engine/annotation.py b/cvat/apps/engine/annotation.py index 9994c523..acaf8896 100644 --- a/cvat/apps/engine/annotation.py +++ b/cvat/apps/engine/annotation.py @@ -1505,11 +1505,17 @@ class _AnnotationForSegment(_Annotation): self.points_paths = annotation.points_paths @plugin_decorator -@transaction.atomic def _dump(tid, data_format, scheme, host, plugin_meta_data): - db_task = models.Task.objects.select_for_update().get(id=tid) - annotation = _AnnotationForTask(db_task) - annotation.init_from_db() + # For big tasks dump function may run for a long time and + # we dont need to acquire lock after _AnnotationForTask instance + # has been initialized from DB. + # But there is the bug with corrupted dump file in case 2 or more dump request received at the same time. + # https://github.com/opencv/cvat/issues/217 + with transaction.atomic(): + db_task = models.Task.objects.select_for_update().get(id=tid) + annotation = _AnnotationForTask(db_task) + annotation.init_from_db() + annotation.dump(data_format, scheme, host, plugin_meta_data) def _calc_box_area(box):