Skip to content

fix: restructure can_redeem to gracefully handle error#108

Open
kiram15 wants to merge 4 commits into
mainfrom
kiram15/on-call
Open

fix: restructure can_redeem to gracefully handle error#108
kiram15 wants to merge 4 commits into
mainfrom
kiram15/on-call

Conversation

@kiram15

@kiram15 kiram15 commented Mar 20, 2026

Copy link
Copy Markdown
Contributor

Description:
models.py: Separate the get_content_metadata fetch into its own try/except, catching HTTPError and raising ContentPriceNullException instead. This normalizes the exception type for all callers.

subsidy_access_policy.py: The original single try/except ContentPriceNullException block covered all three branches (resolved_policy, successful_redemptions, else) and always raised a RedemptionRequestException on failure. For a learner who has already redeemed, a missing catalog entry is a data/catalog mismatch that should not fail the request.

Jira:
ENT-11649

Merge checklist:

  • ./manage.py makemigrations has been run
    • Note: This must be run if you modified any models.
      • It may or may not make a migration depending on exactly what you modified, but it should still be run.

Post merge:

  • Ensure that your changes went out to the stage instance
  • Deploy to prod instance

@kiram15 kiram15 requested review from a team as code owners March 20, 2026 06:19
Copilot AI review requested due to automatic review settings March 20, 2026 06:19

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 restructures list-price fetching and error handling so can_redeem can treat missing catalog/metadata differently depending on whether the learner can redeem vs has already redeemed.

Changes:

  • SubsidyAccessPolicy.get_list_price now wraps HTTPError from content-metadata fetch as ContentPriceNullException.
  • can_redeem now uses separate error-handling paths for resolved_policy, successful_redemptions, and the non-redeemable/no-redemption case, avoiding request failure for already-redeemed content with missing catalog entries.
  • Adds warning logging for the already-redeemed + missing price scenario.

Reviewed changes

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

File Description
enterprise_access/apps/subsidy_access_policy/models.py Normalizes metadata-fetch HTTP failures into ContentPriceNullException for list-price computation.
enterprise_access/apps/api/v1/views/subsidy_access_policy.py Refactors can_redeem list-price logic to avoid failing requests for already-redeemed content when metadata is missing.

Comment thread enterprise_access/apps/api/v1/views/subsidy_access_policy.py
Comment thread enterprise_access/apps/api/v1/views/subsidy_access_policy.py
@codecov

codecov Bot commented Mar 20, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.26%. Comparing base (dfdeddf) to head (38aee72).
⚠️ Report is 74 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #108      +/-   ##
==========================================
+ Coverage   84.01%   86.26%   +2.24%     
==========================================
  Files         144      153       +9     
  Lines       12226    12670     +444     
  Branches     1170     1211      +41     
==========================================
+ Hits        10272    10930     +658     
+ Misses       1625     1425     -200     
+ Partials      329      315      -14     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@brobro10000 brobro10000 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Once its merged, validate down stream consumers (course about page) is still receiving the expected messaging related to subsidy type, and catalog inclusion 👍🏽 . I would wait for either @pwnage101 or @iloveagent57 for final approval, but looks good on my end.

Comment thread enterprise_access/apps/subsidy_access_policy/models.py
Comment thread enterprise_access/apps/api/v1/views/subsidy_access_policy.py
Copilot AI review requested due to automatic review settings March 24, 2026 21:21

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

Comment thread enterprise_access/apps/subsidy_access_policy/models.py
Comment thread enterprise_access/apps/api/v1/views/subsidy_access_policy.py
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.

5 participants