From d9dd84c5ddb345e08b61c53efaa0b35d3e65f856 Mon Sep 17 00:00:00 2001 From: Suryansh Pathak <34577232+Suryansh5545@users.noreply.github.com> Date: Fri, 11 Aug 2023 03:22:01 +0530 Subject: [PATCH] [BugFix] Fix duplicate leaderboard data entry creation on resume (#4082) * fix leaderboard_data being duplicated * Fix flake8 issue * Update utils.py --------- Co-authored-by: Gunjan Chhablani --- apps/jobs/views.py | 70 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 54 insertions(+), 16 deletions(-) diff --git a/apps/jobs/views.py b/apps/jobs/views.py index 75d4a0833c..8dab8ece82 100644 --- a/apps/jobs/views.py +++ b/apps/jobs/views.py @@ -1208,15 +1208,34 @@ def update_submission(request, challenge_pk): response_data, status=status.HTTP_400_BAD_REQUEST ) + try: + leaderboard_data = get_leaderboard_data_model( + submission_pk, challenge_phase_split.pk + ) + except LeaderboardData.DoesNotExist: + leaderboard_data = None + data = {"result": accuracies} - serializer = CreateLeaderboardDataSerializer( - data=data, - context={ - "challenge_phase_split": challenge_phase_split, - "submission": submission, - "request": request, - }, - ) + if leaderboard_data is not None: + serializer = CreateLeaderboardDataSerializer( + leaderboard_data, + data=data, + partial=True, + context={ + "challenge_phase_split": challenge_phase_split, + "submission": submission, + "request": request, + }, + ) + else: + serializer = CreateLeaderboardDataSerializer( + data=data, + context={ + "challenge_phase_split": challenge_phase_split, + "submission": submission, + "request": request, + }, + ) if serializer.is_valid(): leaderboard_data_list.append(serializer) else: @@ -1585,15 +1604,34 @@ def update_partially_evaluated_submission(request, challenge_pk): response_data, status=status.HTTP_400_BAD_REQUEST ) + try: + leaderboard_data = get_leaderboard_data_model( + submission_pk, challenge_phase_split.pk + ) + except LeaderboardData.DoesNotExist: + leaderboard_data = None + data = {"result": accuracies} - serializer = CreateLeaderboardDataSerializer( - data=data, - context={ - "challenge_phase_split": challenge_phase_split, - "submission": submission, - "request": request, - }, - ) + if leaderboard_data is not None: + serializer = CreateLeaderboardDataSerializer( + leaderboard_data, + data=data, + partial=True, + context={ + "challenge_phase_split": challenge_phase_split, + "submission": submission, + "request": request, + }, + ) + else: + serializer = CreateLeaderboardDataSerializer( + data=data, + context={ + "challenge_phase_split": challenge_phase_split, + "submission": submission, + "request": request, + }, + ) if serializer.is_valid(): leaderboard_data_list.append(serializer) else: