Skip to content

Commit

Permalink
Revert "[BugFix] Make leaderboardata is disabled nullable" (#4212)
Browse files Browse the repository at this point in the history
* Revert "[Backend] Make leaderboardata is disabled nullable (#4210)"

This reverts commit 542caa0.

* Add the alter migrations

* Fix missing return
  • Loading branch information
gchhablani authored Nov 8, 2023
1 parent 0bab4f3 commit 403ebfe
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.20 on 2023-11-08 17:36

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('challenges', '0108_alter_leaderboarddata_is_disabled_null'),
]

operations = [
migrations.AlterField(
model_name='leaderboarddata',
name='is_disabled',
field=models.BooleanField(default=False),
),
]
2 changes: 1 addition & 1 deletion apps/challenges/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ class LeaderboardData(TimeStampedModel):
submission = models.ForeignKey("jobs.Submission", on_delete=models.CASCADE)
leaderboard = models.ForeignKey("Leaderboard", on_delete=models.CASCADE)
result = JSONField()
is_disabled = models.BooleanField(default=False, null=True)
is_disabled = models.BooleanField(default=False)
error = JSONField(null=True, blank=True)

def __str__(self):
Expand Down
6 changes: 1 addition & 5 deletions apps/challenges/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
from django.db import transaction
from django.http import HttpResponse
from django.utils import timezone
from django.db.models import Q

from rest_framework import permissions, status
from rest_framework.decorators import (
Expand Down Expand Up @@ -4707,10 +4706,7 @@ def get_leaderboard_data(request, challenge_phase_split_pk):
return Response(response_data, status=status.HTTP_401_UNAUTHORIZED)
try:
challenge_phase_split = get_challenge_phase_split_model(challenge_phase_split_pk)
leaderboard_data = LeaderboardData.objects.filter(
Q(is_disabled=False) | Q(is_disabled__isnull=True),
challenge_phase_split=challenge_phase_split
)
leaderboard_data = LeaderboardData.objects.filter(challenge_phase_split=challenge_phase_split, is_disabled=False)
except LeaderboardData.DoesNotExist:
response_data = {
"error": "Leaderboard data not found!"
Expand Down
4 changes: 2 additions & 2 deletions apps/jobs/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ def calculate_distinct_sorted_leaderboard_data(
leaderboard_data = LeaderboardData.objects.exclude(
Q(submission__created_by__email__in=challenge_hosts_emails)
& Q(submission__is_baseline=False)
).filter(Q(is_disabled=False) | Q(is_disabled__isnull=True))
).filter(is_disabled=False)

# Get all the successful submissions related to the challenge phase split
all_valid_submission_status = [Submission.FINISHED]
Expand Down Expand Up @@ -517,9 +517,9 @@ def get_leaderboard_data_model(submission_pk, challenge_phase_split_pk):
[Class Object] -- LeaderboardData model object
"""
leaderboard_data = LeaderboardData.objects.get(
Q(is_disabled=False) | Q(is_disabled__isnull=True),
submission=submission_pk,
challenge_phase_split__pk=challenge_phase_split_pk,
is_disabled=False,
)
return leaderboard_data

Expand Down
6 changes: 1 addition & 5 deletions apps/jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
from django.db import transaction, IntegrityError
from django.db.models import Count
from django.utils import timezone
from django.db.models import Q

from rest_framework_expiring_authtoken.authentication import (
ExpiringTokenAuthentication,
Expand Down Expand Up @@ -2304,10 +2303,7 @@ def update_leaderboard_data(request, leaderboard_data_pk):
"""

try:
leaderboard_data = LeaderboardData.objects.get(
Q(is_disabled=False) | Q(is_disabled__isnull=True),
pk=leaderboard_data_pk
)
leaderboard_data = LeaderboardData.objects.get(pk=leaderboard_data_pk, is_disabled=False)
except LeaderboardData.DoesNotExist:
response_data = {"error": "Leaderboard data does not exist"}
return Response(response_data, status=status.HTTP_404_NOT_FOUND)
Expand Down

0 comments on commit 403ebfe

Please sign in to comment.