Skip to content

fix: Algolia reindexing for program and course#64

Merged
skumargupta83 merged 1 commit into
masterfrom
rgopalrao/algolia-fix
Jul 24, 2026
Merged

fix: Algolia reindexing for program and course#64
skumargupta83 merged 1 commit into
masterfrom
rgopalrao/algolia-fix

Conversation

@rgopalrao-sonata-png

@rgopalrao-sonata-png rgopalrao-sonata-png commented Jul 24, 2026

Copy link
Copy Markdown

fix: compute Program.b2c_subscription_inclusion so it isn't always False in Algolia

Summary

This PR fixes an issue where Program.b2c_subscription_inclusion was never computed and therefore always remained at its database default value of False. Unlike Course.b2c_subscription_inclusion, which is populated through the course data loader, the program-level field was never updated, causing Algolia to index all programs with b2c_subscription_inclusion=False regardless of their associated courses.

Changes

  • Added Program._check_b2c_subscription_inclusion() following the same pattern as the existing _check_enterprise_subscription_inclusion() implementation.
  • Wired the B2C subscription inclusion computation into both Program.save() paths (publishable and non-publishable flows).
  • Implemented program-level inclusion logic:
    • A program is considered B2C subscription eligible if any associated course has b2c_subscription_inclusion=True.
    • Program types excluded from enterprise catalog eligibility (Bachelors, Masters, and Doctorate) are also excluded from B2C subscription inclusion, matching existing enterprise subscription behavior.
  • Added b2c_subscription_inclusion to ProgramAdmin.readonly_fields since the value is now system-computed rather than manually managed.
  • Removed the obsolete b2c_subscription_inclusion property override from AlgoliaProxyCourse in algolia_models.py.

Why

Program.b2c_subscription_inclusion was never calculated, causing all program records to be indexed in Algolia with a value of False. 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

  • Updated ProgramTests.test_b2c_subscription_inclusion
  • Updated ProgramTests.test_b2c_subscription_exclusion

Both tests now validate the new computed behavior:

  • Inclusion when at least one associated course is B2C subscription eligible.
  • Exclusion for program types that are intentionally filtered out.

Validation Results

  • test_models.py full suite: 338 passed
  • test_algolia_models.py + test_admin.py: 138 passed
    • Excluding pre-existing, unrelated Selenium/Firefox driver failures in the sandbox environment.
  • Linting: Clean on all modified files

Copilot AI review requested due to automatic review settings July 24, 2026 08:53

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 populate Program.b2c_subscription_inclusion during Program.save().
  • Update program model tests to validate program-level B2C inclusion semantics (ANY included course) and type-based exclusions.
  • Remove the b2c_subscription_inclusion property override from AlgoliaProxyCourse and 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.

Comment thread course_discovery/apps/course_metadata/models.py Outdated
Comment thread course_discovery/apps/course_metadata/models.py
Copilot AI review requested due to automatic review settings July 24, 2026 09:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

Comment thread course_discovery/apps/course_metadata/algolia_models.py

@2usatishkumar 2usatishkumar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@skumargupta83

Copy link
Copy Markdown

Hi @2usatishkumar,
Regarding the code added by @rjv31 around lines 3990 and 3999, it is used to restrict the selection of course runs to only those courses that are not included in b2c_subscription_inclusion."

"Additionally, in admin.py (around line 454), b2c_subscription_inclusion was added as a read-only field.
This change is not related to Algolia. The suggestion shared was specifically to make the field read-only in the admin interface.

@2usatishkumar
2usatishkumar self-requested a review July 24, 2026 13:10

@2usatishkumar 2usatishkumar left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved for testing!

@skumargupta83
skumargupta83 merged commit 9b0be8b into master Jul 24, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants