Skip to content

feat: B2C Subscription Inclusion Flag for Program Algolia Reindex#60

Closed
skumargupta83 wants to merge 2 commits into
masterfrom
SUBS/ENHA-820-Algolia-Reindex-On-Program-3
Closed

feat: B2C Subscription Inclusion Flag for Program Algolia Reindex#60
skumargupta83 wants to merge 2 commits into
masterfrom
SUBS/ENHA-820-Algolia-Reindex-On-Program-3

Conversation

@skumargupta83

Copy link
Copy Markdown

https://2u-internal.atlassian.net/browse/SUBS-820
Ensure Program subscription data, including the B2C Subscription Inclusion flag, is indexed in Algolia so eligible Programs can be Sync.

Program subscription flag is indexed.
Index updates after Program changes.
Ensure program subscription data is successfully synchronized with the corresponding Algolia product index.

Copilot AI review requested due to automatic review settings July 23, 2026 14:12

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 aims to ensure the B2C Subscription Inclusion flag is correctly surfaced for Algolia indexing so that subscription-eligible Courses/Programs can be synchronized into the Algolia product index.

Changes:

  • Update b2c_subscription_inclusion accessors on Algolia proxy models.
  • Add tests intended to verify that b2c_subscription_inclusion is read from the underlying persisted product state.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
course_discovery/apps/course_metadata/algolia_models.py Changes how b2c_subscription_inclusion is retrieved on Algolia proxy models.
course_discovery/apps/course_metadata/tests/test_algolia_models.py Adds new tests for retrieving b2c_subscription_inclusion from the underlying product.
Comments suppressed due to low confidence (2)

course_discovery/apps/course_metadata/algolia_models.py:757

  • AlgoliaProxyProgram.b2c_subscription_inclusion now falls back to self.product.b2c_subscription_inclusion, but AlgoliaProxyProgram instances don’t have a product attribute. This can raise AttributeError if _b2c_subscription_inclusion isn’t present (e.g., when the field is deferred/not loaded).
    def b2c_subscription_inclusion(self):
        """Return the b2c_subscription_inclusion value from the underlying Program instance."""
        return getattr(self, '_b2c_subscription_inclusion', self.product.b2c_subscription_inclusion)

course_discovery/apps/course_metadata/tests/test_algolia_models.py:1014

  • AlgoliaProxyProgram(product=program) will raise a TypeError because product isn’t a model field and AlgoliaProxyProgram doesn’t accept it in __init__. The test should fetch the proxy model instance via the ORM instead.
        program = ProgramFactory(partner=self.__class__.edxPartner, b2c_subscription_inclusion=True)
        proxy_program = AlgoliaProxyProgram(product=program)
        assert proxy_program.b2c_subscription_inclusion is True

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +493 to +495
def b2c_subscription_inclusion(self):
"""Return the stored b2c_subscription_inclusion value for persistence and Algolia indexing."""
return self.__dict__.get('_b2c_subscription_inclusion', False)
"""Return the b2c_subscription_inclusion value from the underlying Course instance."""
return getattr(self, '_b2c_subscription_inclusion', self.product.b2c_subscription_inclusion)
Comment on lines +999 to +1008
def test_b2c_subscription_inclusion_retrieved_from_product_for_courses(self):
"""Test that b2c_subscription_inclusion is retrieved from the underlying product for courses."""
course = CourseFactory(partner=self.__class__.edxPartner, b2c_subscription_inclusion=True)
proxy_course = AlgoliaProxyCourse(product=course)
assert proxy_course.b2c_subscription_inclusion is True

course.b2c_subscription_inclusion = False
course.save()
proxy_course_updated = AlgoliaProxyCourse(product=course)
assert proxy_course_updated.b2c_subscription_inclusion is False

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 2 out of 2 changed files in this pull request and generated 1 comment.

Comment on lines +999 to +1011
def test_b2c_subscription_inclusion_retrieved_from_product_for_courses(self):
"""Test that b2c_subscription_inclusion is retrieved from the underlying course model value."""
course = AlgoliaProxyCourseFactory(partner=self.__class__.edxPartner, b2c_subscription_inclusion=True)
assert course.b2c_subscription_inclusion is True

proxy_course = AlgoliaProxyCourse.objects.get(pk=course.pk)
assert proxy_course.b2c_subscription_inclusion is True

course.b2c_subscription_inclusion = False
course.save()
proxy_course_updated = AlgoliaProxyCourse.objects.get(pk=course.pk)
assert proxy_course_updated.b2c_subscription_inclusion is False

Copilot AI review requested due to automatic review settings July 23, 2026 14:37

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 2 out of 2 changed files in this pull request and generated no new comments.

Copilot AI review requested due to automatic review settings July 23, 2026 14:42
@skumargupta83
skumargupta83 force-pushed the SUBS/ENHA-820-Algolia-Reindex-On-Program-3 branch from a04f9d4 to 11b5c79 Compare July 23, 2026 14:42

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 2 out of 2 changed files in this pull request and generated no new comments.

Comments suppressed due to low confidence (3)

course_discovery/apps/course_metadata/algolia_models.py:496

  • b2c_subscription_inclusion currently calls getattr(self, '_b2c_subscription_inclusion', self.product.b2c_subscription_inclusion). The default argument is evaluated eagerly, so this will always try to access self.product even when _b2c_subscription_inclusion is set. AlgoliaProxyCourse instances do not have a product attribute, so this will raise AttributeError during indexing/saving.
    @property
    def b2c_subscription_inclusion(self):
        """Return the b2c_subscription_inclusion value from the underlying Course instance in Course."""
        return getattr(self, '_b2c_subscription_inclusion', self.product.b2c_subscription_inclusion)

course_discovery/apps/course_metadata/algolia_models.py:758

  • Same issue as AlgoliaProxyCourse: the default argument to getattr(...) is evaluated eagerly, and AlgoliaProxyProgram instances do not define self.product. This will raise AttributeError and break Algolia indexing / persistence.
    @property
    def b2c_subscription_inclusion(self):
        """Return the b2c_subscription_inclusion value from the underlying Program instance for the Program."""
        return getattr(self, '_b2c_subscription_inclusion', self.product.b2c_subscription_inclusion)

course_discovery/apps/course_metadata/tests/test_algolia_models.py:1003

  • These new tests instantiate AlgoliaProxyCourse(product=course) / AlgoliaProxyProgram(product=program), but those proxy Django models don't accept a product kwarg (only AlgoliaProxyProduct does). This will raise TypeError and the tests won't run. Consider asserting persistence/updates using the proxy models directly instead.
    def test_b2c_subscription_inclusion_retrieved_from_product_for_courses(self):
        """Test that b2c_subscription_inclusion is retrieved from the underlying product for courses."""
        course = CourseFactory(partner=self.__class__.edxPartner, b2c_subscription_inclusion=True)
        proxy_course = AlgoliaProxyCourse(product=course)
        assert proxy_course.b2c_subscription_inclusion is True

…d self.product on AlgoliaProxyCourse/AlgoliaProxyProgram

The commit 11b5c79 changed AlgoliaProxyCourse.b2c_subscription_inclusion and
AlgoliaProxyProgram.b2c_subscription_inclusion getters to use:
  getattr(self, '_b2c_subscription_inclusion', self.product.b2c_subscription_inclusion)

However, AlgoliaProxyCourse and AlgoliaProxyProgram are Django proxy models that
inherit from Course and Program directly — they have no 'self.product' attribute.
Only AlgoliaProxyProduct (which wraps a product in its __init__) has self.product.

This caused AttributeError on every test because the property was evaluated by
Django during model saves, breaking all tests in TestAlgoliaProxyCourse and
TestAlgoliaProxyProgram.

Fix:
- Revert AlgoliaProxyCourse.b2c_subscription_inclusion getter to
  self.__dict__.get('_b2c_subscription_inclusion', False)
- Revert AlgoliaProxyProgram.b2c_subscription_inclusion getter to
  self.__dict__.get('_b2c_subscription_inclusion',
    self.__dict__.get('b2c_subscription_inclusion', False))
- Fix the new tests to load proxy instances via .objects.get(pk=...) from the
  database instead of incorrectly passing product= to the constructor
Copilot AI review requested due to automatic review settings July 23, 2026 15:51

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.

Comments suppressed due to low confidence (1)

course_discovery/apps/course_metadata/tests/test_algolia_models.py:999

  • This test exercises AlgoliaProxyCourse but is placed inside TestAlgoliaProxyProgram. For consistency with the rest of this file (course-related assertions live under TestAlgoliaProxyCourse), move this test into the TestAlgoliaProxyCourse class to keep course vs program behavior separated and easier to maintain.
    def test_b2c_subscription_inclusion_retrieved_from_product_for_courses(self):

Comment on lines +1001 to +1003
course = CourseFactory(partner=self.__class__.edxPartner, b2c_subscription_inclusion=True)
proxy_course = AlgoliaProxyCourse.objects.get(pk=course.pk)
assert proxy_course.b2c_subscription_inclusion is True
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.

3 participants