Skip to content

Commit

Permalink
[BugFix] Fix duplicate leaderboard data entry creation on resume (#4205)
Browse files Browse the repository at this point in the history
* fix leaderboard_data being duplicated

* Fix flake8 issue

* Update utils.py

---------

Co-authored-by: Gunjan Chhablani <[email protected]>
  • Loading branch information
Suryansh5545 and gchhablani authored Nov 8, 2023
1 parent 542caa0 commit 0bab4f3
Showing 1 changed file with 54 additions and 16 deletions.
70 changes: 54 additions & 16 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -1209,15 +1209,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:
Expand Down Expand Up @@ -1586,15 +1605,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:
Expand Down

0 comments on commit 0bab4f3

Please sign in to comment.