Skip to content

Commit

Permalink
fix: use coerce_to_parent_course when fetching content for default en…
Browse files Browse the repository at this point in the history
…rollment intentions

ENT-9840
  • Loading branch information
pwnage101 committed Jan 22, 2025
1 parent 215e57a commit 60ddf2a
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
4 changes: 3 additions & 1 deletion enterprise/api_client/enterprise_catalog.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,13 +418,15 @@ def get_customer_content_metadata_content_identifier(self, enterprise_uuid, cont
return {}

Check warning on line 418 in enterprise/api_client/enterprise_catalog.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api_client/enterprise_catalog.py#L418

Added line #L418 was not covered by tests

@UserAPIClient.refresh_token
def get_content_metadata_content_identifier(self, content_id):
def get_content_metadata_content_identifier(self, content_id, coerce_to_parent_course=False):
"""
Return the content metadata for the content_id.
"""
try:
api_url = self.get_api_url(self.CONTENT_METADATA_IDENTIFIER_ENDPOINT)
query_params = {"content_identifiers": content_id}

Check warning on line 427 in enterprise/api_client/enterprise_catalog.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api_client/enterprise_catalog.py#L425-L427

Added lines #L425 - L427 were not covered by tests
if coerce_to_parent_course:
query_params["coerce_to_parent_course"] = True
response = self.client.get(

Check warning on line 430 in enterprise/api_client/enterprise_catalog.py

View check run for this annotation

Codecov / codecov/patch

enterprise/api_client/enterprise_catalog.py#L429-L430

Added lines #L429 - L430 were not covered by tests
api_url,
params=query_params,
Expand Down
10 changes: 6 additions & 4 deletions enterprise/content_metadata/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
DEFAULT_CACHE_TIMEOUT = getattr(settings, 'CONTENT_METADATA_CACHE_TIMEOUT', 60 * 5)


def get_and_cache_content_metadata(content_key, timeout=None):
def get_and_cache_content_metadata(content_key, timeout=None, coerce_to_parent_course=False):
"""
Returns the metadata corresponding to the requested ``content_key``
REGARDLESS of catalog/customer associations.
Expand All @@ -28,15 +28,16 @@ def get_and_cache_content_metadata(content_key, timeout=None):
Raises: An HTTPError if there's a problem getting the content metadata
via the enterprise-catalog service.
"""
cache_key = versioned_cache_key('get_content_metadata_content_identifier', content_key)
cache_key = versioned_cache_key('get_content_metadata_content_identifier', content_key, coerce_to_parent_course)
cached_response = TieredCache.get_cached_response(cache_key)
if cached_response.is_found:
logger.info(f'cache hit for content_key {content_key}')
logger.info(f'cache hit for content_key {content_key} and coerce_to_parent_course={coerce_to_parent_course}')
return cached_response.value

try:
result = EnterpriseCatalogApiClient().get_content_metadata_content_identifier(
content_id=content_key,
coerce_to_parent_course=coerce_to_parent_course,
)
except HTTPError as exc:
raise exc

Check warning on line 43 in enterprise/content_metadata/api.py

View check run for this annotation

Codecov / codecov/patch

enterprise/content_metadata/api.py#L42-L43

Added lines #L42 - L43 were not covered by tests
Expand All @@ -46,8 +47,9 @@ def get_and_cache_content_metadata(content_key, timeout=None):
return {}

Check warning on line 47 in enterprise/content_metadata/api.py

View check run for this annotation

Codecov / codecov/patch

enterprise/content_metadata/api.py#L46-L47

Added lines #L46 - L47 were not covered by tests

logger.info(
'Fetched catalog for content_key %s. Result = %s',
'Fetched catalog for content_key %s and coerce_to_parent_course=%s. Result = %s',
content_key,
coerce_to_parent_course,
result,
)
TieredCache.set_all_tiers(cache_key, result, timeout or DEFAULT_CACHE_TIMEOUT)
Expand Down
1 change: 1 addition & 0 deletions enterprise/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2554,6 +2554,7 @@ def content_metadata_for_content_key(self):
try:
return get_and_cache_content_metadata(
content_key=self.content_key,
coerce_to_parent_course=True,
)
except HTTPError as e:
LOGGER.error(
Expand Down

0 comments on commit 60ddf2a

Please sign in to comment.