fix: ignore non-restricted runs listed in restricted_runs_allowed (EN… - #192
Open
gshivajibiradar wants to merge 2 commits into
Open
gshivajibiradar wants to merge 2 commits into
gshivajibiradar wants to merge 2 commits into
Conversation
…T-12315) RestrictedCourseMetadata.restricted_runs_for_course() now requires a run to have a restriction_type, in addition to being listed in the content filter's restricted_runs_allowed. Listed runs without a restriction_type are ignored and a warning naming the run, course and catalog query is logged. This stops public runs from being duplicated in the per-query JSON and from getting a RestrictedRunAllowedForRestrictedCourse row that hides them from other catalogs. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #192 +/- ##
==========================================
+ Coverage 85.43% 85.45% +0.01%
==========================================
Files 109 109
Lines 6799 6807 +8
Branches 831 834 +3
==========================================
+ Hits 5809 5817 +8
Misses 831 831
Partials 159 159 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
fix: ignore non-restricted runs listed in restricted_runs_allowed (ENT-12315)
Description
Problem
RestrictedCourseMetadata.restricted_runs_for_course()previously identified restricted runs solely based on whether the run key was present in the catalog query'srestricted_runs_allowedconfiguration. It did not validate the run'srestriction_type.If a non-restricted (public) run was mistakenly included in
restricted_runs_allowed, it could be incorrectly treated as restricted, causing:Duplicate entries in the per-query
RestrictedCourseMetadataJSON.An incorrect
RestrictedRunAllowedForRestrictedCourserelationship to be created.The public run to be treated as restricted globally, causing it to be hidden from v1 responses and from
contains_content_keys/get_content_metadatafor other catalogs.A production issue where
course-v1:LSE+PRE+3T2026(non-restricted) was configured alongsidecourse-v1:LSE+PRE+3T2026a(restricted), resulting in 404 responses from the enterprise-subsidy content metadata endpoint.Fix
Updated
restricted_runs_for_course()to include a run only when both conditions are met:The run key is present in
restricted_runs_allowedfor the course.run.get("restriction_type")is notNone.Runs listed in
restricted_runs_allowedwithout arestriction_typeare now ignored, and aWARNINGis logged with the run key, course key, and catalog query ID/UUID.Valid restricted runs continue to behave as before.
This prevents incorrectly configured non-restricted runs from being treated as restricted and affecting other catalogs.
Changes
enterprise_catalog/apps/catalog/models.pyAdded
restriction_typevalidation inrestricted_runs_for_course().Added warning logging for ignored non-restricted runs.
enterprise_catalog/apps/catalog/tests/test_models.pyAdded test coverage to verify that:
Valid restricted runs continue to be included without warnings.
Non-restricted runs are excluded and generate a warning.
Mixed configurations return only the valid restricted run.
Non-restricted runs are not duplicated in the generated JSON.
No
RestrictedRunAllowedForRestrictedCourserelationship is created for non-restricted runs.Testing
pytest enterprise_catalog/apps/catalog enterprise_catalog/apps/api: 764 passedChanged lines are fully covered by the new tests.
pycodestylepasses.Remaining
pylintandisortfindings are unrelated to this change.PR Verification
Verified Requirements
Requirement | Evidence -- | -- Ignores runs where restriction_type is None | models.py:893-907 skips a listed run when run.get(COURSE_RUN_RESTRICTION_TYPE_KEY) is None. Warning includes run key, course key, query ID, and UUID | The warning includes all four values, and test_restricted_runs_for_course_ignores_non_restricted_run verifies them. No RestrictedRunAllowedForRestrictedCourse relationship for non-restricted runs | update_course_run_relationships builds relationships from the filtered restricted_run_dicts, so the non-restricted run is excluded. Valid restricted runs remain unchanged | test_restricted_runs_for_course_includes_restricted_run verifies no warning is generated, and the existing test_store_record_with_query continues to pass.Relevant Tests
The following tests are covered in
TestRestrictedRunsModels:test_restricted_runs_for_course_includes_restricted_runtest_restricted_runs_for_course_ignores_non_restricted_runtest_restricted_runs_for_course_mixed_listtest_non_restricted_run_in_restricted_runs_allowed_has_no_adverse_effectThe first test is also a regression guard and passes on the base branch; the remaining tests specifically validate the fix.
PR Evidence Command
Run from the repository root:
Expected result:
For broader regression coverage:
Result: 764 passed.
Jira
https://2u-internal.atlassian.net/browse/ENT-12315