Skip to content

Commit

Permalink
Fix GT job creation races (#7096)
Browse files Browse the repository at this point in the history
It's possible to get more than 1 GT job in a task in the case of
concurrent creation requests.
This PR fixes this by introducing a task row-level lock in the DB for
the update transaction.

- Fixed GT job creation race condition
  • Loading branch information
zhiltsov-max authored Nov 7, 2023
1 parent 92f5181 commit 1ef6ba0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelog.d/20231104_113802_mzhiltsov_fix_atomic_uses.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
### Fixed

- Data race condition during GT job creation
(<https://github.com/opencv/cvat/pull/7096>)
2 changes: 1 addition & 1 deletion cvat/apps/engine/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ def to_representation(self, instance):
@transaction.atomic
def create(self, validated_data):
task_id = validated_data.pop('task_id')
task = models.Task.objects.get(pk=task_id)
task = models.Task.objects.select_for_update().get(pk=task_id)

if validated_data["type"] == models.JobType.GROUND_TRUTH:
if not task.data:
Expand Down

0 comments on commit 1ef6ba0

Please sign in to comment.