Skip to content

fix: ignore non-restricted runs listed in restricted_runs_allowed (EN… - #192

Open
gshivajibiradar wants to merge 2 commits into
masterfrom
ENT-12315-ignore-non-restricted-runs
Open

gshivajibiradar wants to merge 2 commits into
masterfrom
ENT-12315-ignore-non-restricted-runs

Conversation

@gshivajibiradar

@gshivajibiradar gshivajibiradar commented Oct 5, 2026 •

Copy link
Copy Markdown

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's restricted_runs_allowed configuration. It did not validate the run's restriction_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 RestrictedCourseMetadata JSON.

  • An incorrect RestrictedRunAllowedForRestrictedCourse relationship 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_metadata for other catalogs.

  • A production issue where course-v1:LSE+PRE+3T2026 (non-restricted) was configured alongside course-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:

  1. The run key is present in restricted_runs_allowed for the course.

  2. run.get("restriction_type") is not None.

Runs listed in restricted_runs_allowed without a restriction_type are now ignored, and a WARNING is 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.py

  • Added restriction_type validation in restricted_runs_for_course().

  • Added warning logging for ignored non-restricted runs.

enterprise_catalog/apps/catalog/tests/test_models.py

Added 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 RestrictedRunAllowedForRestrictedCourse relationship is created for non-restricted runs.

Testing

  • pytest enterprise_catalog/apps/catalog enterprise_catalog/apps/api: 764 passed

  • Changed lines are fully covered by the new tests.

  • pycodestyle passes.

  • Remaining pylint and isort findings 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. image

Relevant Tests

The following tests are covered in TestRestrictedRunsModels:

  • test_restricted_runs_for_course_includes_restricted_run

  • test_restricted_runs_for_course_ignores_non_restricted_run

  • test_restricted_runs_for_course_mixed_list

  • test_non_restricted_run_in_restricted_runs_allowed_has_no_adverse_effect

The 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:

docker exec -e DJANGO_SETTINGS_MODULE=enterprise_catalog.settings.test edx.devstack.enterprise.catalog.worker \
  bash -c 'cd /edx/app/enterprise-catalog && pytest enterprise_catalog/apps/catalog/tests/test_models.py \
  -k "restricted_runs_for_course or non_restricted_run_in_restricted_runs_allowed" -v --no-cov -p no:cacheprovider'

Expected result:

4 passed

For broader regression coverage:

pytest enterprise_catalog/apps/catalog enterprise_catalog/apps/api --no-cov

Result: 764 passed.

Jira

https://2u-internal.atlassian.net/browse/ENT-12315

…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>
@gshivajibiradar
gshivajibiradar requested review from a team as code owners October 5, 2026 05:14
@codecov

codecov Bot commented Oct 5, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 85.45%. Comparing base (0f6880b) to head (1df668f).
⚠️ Report is 1 commits behind head on master.

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.
📢 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.

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.

1 participant