|
24 | 24 | from help_tokens.core import HelpUrlExpert |
25 | 25 | from lti_consumer.models import CourseAllowPIISharingInLTIFlag |
26 | 26 | from milestones import api as milestones_api |
| 27 | +from opaque_keys import InvalidKeyError |
27 | 28 | from opaque_keys.edx.keys import CourseKey, UsageKey, UsageKeyV2 |
28 | 29 | from opaque_keys.edx.locator import LibraryLocator |
29 | 30 | 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 |
2378 | 2379 | """ |
2379 | 2380 | if not xblock.upstream: |
2380 | 2381 | return None |
2381 | | - upstream_usage_key = UsageKeyV2.from_string(xblock.upstream) |
2382 | 2382 | 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