Merge pull request #28968 from edx/iamsobanjaved/django32-user-api-bool-fix

refactor: use value for filtering indexed boolean field
This commit is contained in:
Muhammad Soban Javed
2021-10-07 17:53:06 +05:00
committed by GitHub

View File

@@ -199,11 +199,15 @@ class RetirementState(models.Model):
@classmethod
def get_dead_end_states(cls):
return cls.objects.filter(is_dead_end_state=True)
# We use models.Value(1) to make use of the indexing on the field. MySQL does not
# support boolean types natively, and checking for False will cause a table scan.
return cls.objects.filter(is_dead_end_state=models.Value(1))
@classmethod
def get_dead_end_state_names_list(cls):
return cls.objects.filter(is_dead_end_state=True).values_list('state_name', flat=True)
# We use models.Value(0) to make use of the indexing on the field. MySQL does not
# support boolean types natively, and checking for False will cause a table scan.
return cls.objects.filter(is_dead_end_state=models.Value(1)).values_list('state_name', flat=True)
@classmethod
def get_state_names_list(cls):