fix: Algolia reindexing for program and course#64
Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes incorrect Algolia indexing for Program.b2c_subscription_inclusion by computing and persisting the value on the Program model (instead of leaving it at the DB default False), and removing the now-unnecessary shadowing behavior in the Algolia proxy for courses.
Changes:
- Add
Program._check_b2c_subscription_inclusion()and populateProgram.b2c_subscription_inclusionduringProgram.save(). - Update program model tests to validate program-level B2C inclusion semantics (ANY included course) and type-based exclusions.
- Remove the
b2c_subscription_inclusionproperty override fromAlgoliaProxyCourseand make the admin field read-only.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
course_discovery/apps/course_metadata/models.py |
Adds program-level B2C inclusion computation and persists it during Program.save(). |
course_discovery/apps/course_metadata/tests/test_models.py |
Updates program tests to validate computed B2C inclusion behavior and exclusions. |
course_discovery/apps/course_metadata/algolia_models.py |
Removes AlgoliaProxyCourse property override so Algolia reads the persisted field directly. |
course_discovery/apps/course_metadata/admin.py |
Makes b2c_subscription_inclusion read-only in the Program admin. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
6d538e6 to
ac0f203
Compare
2usatishkumar
left a comment
There was a problem hiding this comment.
Please check by remove descriptors,creating simple function in def _check_b2c_subscription_inclusion(self):
if not ProgramType.is_enterprise_catalog_program_type(self.type):
return False
return any(course.b2c_subscription_inclusion for course in self.courses.all()) and after line 3990 and 3999 self.b2c_subscription_inclusion = self._check_b2c_subscription_inclusion() in /workspaces/edx-repos/course-discovery/course_discovery/apps/course_metadata/models.py
an din admin.py in line no 454 add 'b2c_subscription_inclusion' as readonly field
|
Hi @2usatishkumar, "Additionally, in admin.py (around line 454), b2c_subscription_inclusion was added as a read-only field. |
fix: compute Program.b2c_subscription_inclusion so it isn't always False in Algolia
Summary
This PR fixes an issue where
Program.b2c_subscription_inclusionwas never computed and therefore always remained at its database default value ofFalse. UnlikeCourse.b2c_subscription_inclusion, which is populated through the course data loader, the program-level field was never updated, causing Algolia to index all programs withb2c_subscription_inclusion=Falseregardless of their associated courses.Changes
Program._check_b2c_subscription_inclusion()following the same pattern as the existing_check_enterprise_subscription_inclusion()implementation.Program.save()paths (publishable and non-publishable flows).b2c_subscription_inclusion=True.Bachelors,Masters, andDoctorate) are also excluded from B2C subscription inclusion, matching existing enterprise subscription behavior.b2c_subscription_inclusiontoProgramAdmin.readonly_fieldssince the value is now system-computed rather than manually managed.b2c_subscription_inclusionproperty override fromAlgoliaProxyCourseinalgolia_models.py.AlgoliaProxyProgramin PR feat: B2C Subscription Inclusion Flag for Program Algolia Reindex #61.Why
Program.b2c_subscription_inclusionwas never calculated, causing all program records to be indexed in Algolia with a value ofFalse. As a result, subscription eligibility information for programs was inaccurate and did not reflect the inclusion status of their associated courses.This change ensures that program-level B2C subscription eligibility is correctly derived, persisted, and indexed.
Testing
Updated Tests
ProgramTests.test_b2c_subscription_inclusionProgramTests.test_b2c_subscription_exclusionBoth tests now validate the new computed behavior:
Validation Results
test_models.pyfull suite: 338 passedtest_algolia_models.py+test_admin.py: 138 passed