fix: restructure can_redeem to gracefully handle error#108
Conversation
There was a problem hiding this comment.
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_pricenow wrapsHTTPErrorfrom content-metadata fetch asContentPriceNullException.can_redeemnow uses separate error-handling paths forresolved_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. |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. 🚀 New features to boost your workflow:
|
brobro10000
left a comment
There was a problem hiding this comment.
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.
Description:
models.py: Separate the
get_content_metadatafetch 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 makemigrationshas been runPost merge: