diff --git a/enterprise_catalog/apps/catalog/models.py b/enterprise_catalog/apps/catalog/models.py index b2a203cc..de154b35 100644 --- a/enterprise_catalog/apps/catalog/models.py +++ b/enterprise_catalog/apps/catalog/models.py @@ -940,8 +940,6 @@ def update_course_run_relationships(self): # We use a set() here, with clear=True, to clear and then reset the related allowed runs # for this restricted course. This is necessary in the case that a previously-allowed # run becomes unassociated from the restricted course. - self.catalog_query.contentmetadata_set.set(restricted_runs, clear=True) - LOGGER.info('Updated restricted runs on catalog query of %s to %s', self, restricted_runs) self.restricted_run_allowed_for_restricted_course.set(restricted_runs, clear=True) LOGGER.info('Updated restricted runs of %s to %s', self, restricted_runs) self.refresh_from_db() diff --git a/enterprise_catalog/apps/catalog/tests/test_models.py b/enterprise_catalog/apps/catalog/tests/test_models.py index a9b7e256..99b4024f 100644 --- a/enterprise_catalog/apps/catalog/tests/test_models.py +++ b/enterprise_catalog/apps/catalog/tests/test_models.py @@ -1437,6 +1437,18 @@ def test_synchronize_restricted_content(self, mock_client): 'content_key', ) ) + + # The catalog_query should not have any content metadata related directly + # to it via the "normal" content_metadata M2M relationship. + self.assertEqual(catalog_query.contentmetadata_set.all().count(), 0) + + # But the catalog_query should have a direct restricted relationship with + # the restricted course. + self.assertEqual( + list(catalog_query.restricted_content_metadata.all()), + [restricted_course], + ) + self.assertEqual( [run.content_key for run in restricted_runs], ['course-v1:edX+course+run2', 'course-v1:edX+course+run3'],