Skip to content

Commit

Permalink
Merge pull request #432 from bento-platform/fix/public-search-fields
Browse files Browse the repository at this point in the history
fix: public_search_fields endpoint not returning values correctly
  • Loading branch information
davidlougheed authored Sep 1, 2023
2 parents 3a20aa8 + 7e3b760 commit 1b0dfed
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
9 changes: 9 additions & 0 deletions chord_metadata_service/patients/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -592,6 +592,15 @@ def test_public_filtering_mapping_for_search_filter(self):
response_obj = response.json()
self.assertEqual(1, response_obj["count"])

@override_settings(CONFIG_PUBLIC=CONFIG_PUBLIC_TEST)
def test_public_overview_sex(self):
response = self.client.get('/api/public_search_fields')
self.assertEqual(response.status_code, status.HTTP_200_OK)
response_obj = response.json()

# overview for sex should have entries due to large cell counts: MALE, FEMALE, UNKNOWN, OTHER
self.assertEqual(len(response_obj["sections"][0]["fields"][0]["options"]), 4) # path to sex field


class PublicFilteringIndividualsTestSmallCellCount(PublicFilteringIndividualsTest):
num_individuals = 3 # below configured test threshold
Expand Down
2 changes: 1 addition & 1 deletion chord_metadata_service/restapi/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ def get_distinct_field_values(field_props: dict) -> list[Any]:
model, field = get_model_and_field(field_props["mapping"])
threshold = get_threshold()

values_with_counts = model.objects.values_list(field).annotate(count=Count(field, distinct=True))
values_with_counts = model.objects.values_list(field).annotate(count=Count(field))
return [val for val, count in values_with_counts if count > threshold]


Expand Down

0 comments on commit 1b0dfed

Please sign in to comment.