diff --git a/backend/services/academics/hiring.py b/backend/services/academics/hiring.py index f1d5f61bc..13b8ccae4 100644 --- a/backend/services/academics/hiring.py +++ b/backend/services/academics/hiring.py @@ -292,7 +292,7 @@ def _load_applicants( } def _load_application_preferences( - self, applications: dict[int, ApplicationEntity] + self, site: CourseSiteEntity, applications: dict[int, ApplicationEntity] ) -> dict[int, int]: """ Loads all application preferences for a given course site. @@ -305,11 +305,16 @@ def _load_application_preferences( """ preferences_query = ( select( - ApplicationReviewEntity.application_id, - func.min(ApplicationReviewEntity.preference), + section_application_table.c.application_id, + func.min(section_application_table.c.preference), + ) + .where(section_application_table.c.application_id.in_(applications.keys())) + .where( + section_application_table.c.section_id.in_( + [section.id for section in site.sections] + ) ) - .where(ApplicationReviewEntity.application_id.in_(applications.keys())) - .group_by(ApplicationReviewEntity.application_id) + .group_by(section_application_table.c.application_id) ) result = self._session.execute(preferences_query) return {row[0]: row[1] + 1 for row in result} @@ -333,7 +338,9 @@ def _to_review_models( application_reviews = self._load_application_reviews(site_entity) applications = self._load_applications(application_reviews) applicants = self._load_applicants(applications) - applicant_preferences = self._load_application_preferences(applications) + applicant_preferences = self._load_application_preferences( + site_entity, applications + ) return [ ApplicationReviewOverview( id=review.id,