Skip to content

Commit 5a97660

Browse files
committed
feat: create component link only for component xblocks
1 parent 0c5d340 commit 5a97660

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

cms/djangoapps/contentstore/utils.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
from help_tokens.core import HelpUrlExpert
2525
from lti_consumer.models import CourseAllowPIISharingInLTIFlag
2626
from milestones import api as milestones_api
27+
from opaque_keys import InvalidKeyError
2728
from opaque_keys.edx.keys import CourseKey, UsageKey, UsageKeyV2
2829
from opaque_keys.edx.locator import LibraryLocator
2930
from openedx_events.content_authoring.data import DuplicatedXBlockData
@@ -2378,19 +2379,22 @@ def create_or_update_xblock_upstream_link(xblock, course_key: str | CourseKey, c
23782379
"""
23792380
if not xblock.upstream:
23802381
return None
2381-
upstream_usage_key = UsageKeyV2.from_string(xblock.upstream)
23822382
try:
2383-
lib_component = get_component_from_usage_key(upstream_usage_key)
2384-
except ObjectDoesNotExist:
2385-
log.error(f"Library component not found for {upstream_usage_key}")
2386-
lib_component = None
2387-
ComponentLink.update_or_create(
2388-
lib_component,
2389-
upstream_usage_key=upstream_usage_key,
2390-
upstream_context_key=str(upstream_usage_key.context_key),
2391-
downstream_context_key=course_key,
2392-
downstream_usage_key=xblock.usage_key,
2393-
version_synced=xblock.upstream_version,
2394-
version_declined=xblock.upstream_version_declined,
2395-
created=created,
2396-
)
2383+
upstream_usage_key = UsageKeyV2.from_string(xblock.upstream)
2384+
try:
2385+
lib_component = get_component_from_usage_key(upstream_usage_key)
2386+
except ObjectDoesNotExist:
2387+
log.error(f"Library component not found for {upstream_usage_key}")
2388+
lib_component = None
2389+
ComponentLink.update_or_create(
2390+
lib_component,
2391+
upstream_usage_key=upstream_usage_key,
2392+
upstream_context_key=str(upstream_usage_key.context_key),
2393+
downstream_context_key=course_key,
2394+
downstream_usage_key=xblock.usage_key,
2395+
version_synced=xblock.upstream_version,
2396+
version_declined=xblock.upstream_version_declined,
2397+
created=created,
2398+
)
2399+
except InvalidKeyError:
2400+
pass

0 commit comments

Comments
 (0)