Skip to content

Commit 8324ca1

Browse files
kdmccormickclaude
andcommitted
refactor: Rename Component.local_key to component_code for openedx-core 0.43.0
Updates callers of get_component_by_key/component_exists_by_key (now _by_code) and switches the local_key kwarg on create_component, create_component_and_version, and related queries to component_code. Also renames component.local_key reads to component.component_code and adjusts a modulestore_migrator container query that filtered on publishable_entity__key (now entity_ref). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent bc671e4 commit 8324ca1

8 files changed

Lines changed: 21 additions & 21 deletions

File tree

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -346,13 +346,13 @@ def _import_structure(
346346
LibraryUsageLocatorV2(target_library.key, block_type, block_id) # type: ignore[abstract]
347347
for block_type, block_id
348348
in content_api.get_components(migration.target.id).values_list(
349-
"component_type__name", "local_key"
349+
"component_type__name", "component_code"
350350
)
351351
),
352352
used_container_slugs=set(
353353
content_api.get_containers(
354354
migration.target.id
355-
).values_list("publishable_entity__key", flat=True)
355+
).values_list("publishable_entity__entity_ref", flat=True)
356356
),
357357
previous_block_migrations=(
358358
get_migration_blocks(source_data.previous_migration.pk)
@@ -932,7 +932,7 @@ def _migrate_component(
932932
try:
933933
component = content_api.get_components(context.target_package_id).get(
934934
component_type=component_type,
935-
local_key=target_key.block_id,
935+
component_code=target_key.block_id,
936936
)
937937
component_existed = True
938938
# Do we have a specific method for this?
@@ -953,7 +953,7 @@ def _migrate_component(
953953
component = content_api.create_component(
954954
context.target_package_id,
955955
component_type=component_type,
956-
local_key=target_key.block_id,
956+
component_code=target_key.block_id,
957957
created=context.created_at,
958958
created_by=context.created_by,
959959
)

cms/djangoapps/modulestore_migrator/tests/test_tasks.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def test_migrate_container_creates_new_container(self):
718718
component_type=content_api.get_or_create_component_type(
719719
"xblock.v1", "problem"
720720
),
721-
local_key="child_problem_1",
721+
component_code="child_problem_1",
722722
created=timezone.now(),
723723
created_by=self.user.id,
724724
)
@@ -734,7 +734,7 @@ def test_migrate_container_creates_new_container(self):
734734
component_type=content_api.get_or_create_component_type(
735735
"xblock.v1", "html"
736736
),
737-
local_key="child_html_1",
737+
component_code="child_html_1",
738738
created=timezone.now(),
739739
created_by=self.user.id,
740740
)
@@ -906,7 +906,7 @@ def test_migrate_container_preserves_child_order(self):
906906
component_type=content_api.get_or_create_component_type(
907907
"xblock.v1", "problem"
908908
),
909-
local_key=f"child_problem_{i}",
909+
component_code=f"child_problem_{i}",
910910
created=timezone.now(),
911911
created_by=self.user.id,
912912
)
@@ -946,7 +946,7 @@ def test_migrate_container_with_mixed_child_types(self):
946946
component_type=content_api.get_or_create_component_type(
947947
"xblock.v1", "problem"
948948
),
949-
local_key="mixed_problem",
949+
component_code="mixed_problem",
950950
created=timezone.now(),
951951
created_by=self.user.id,
952952
)
@@ -962,7 +962,7 @@ def test_migrate_container_with_mixed_child_types(self):
962962
component_type=content_api.get_or_create_component_type(
963963
"xblock.v1", "html"
964964
),
965-
local_key="mixed_html",
965+
component_code="mixed_html",
966966
created=timezone.now(),
967967
created_by=self.user.id,
968968
)
@@ -978,7 +978,7 @@ def test_migrate_container_with_mixed_child_types(self):
978978
component_type=content_api.get_or_create_component_type(
979979
"xblock.v1", "video"
980980
),
981-
local_key="mixed_video",
981+
component_code="mixed_video",
982982
created=timezone.now(),
983983
created_by=self.user.id,
984984
)

openedx/core/djangoapps/content_libraries/api/blocks.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ def _import_staged_block(
425425
component = content_api.create_component( # noqa: F841
426426
learning_package.id,
427427
component_type=component_type,
428-
local_key=usage_key.block_id,
428+
component_code=usage_key.block_id,
429429
created=now,
430430
created_by=user.id,
431431
)
@@ -1046,7 +1046,7 @@ def _create_component_for_block(
10461046
component, component_version = content_api.create_component_and_version(
10471047
learning_package.id,
10481048
component_type=component_type,
1049-
local_key=usage_key.block_id,
1049+
component_code=usage_key.block_id,
10501050
title=display_name,
10511051
created=now,
10521052
created_by=user_id,

openedx/core/djangoapps/content_libraries/api/collections.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,11 +144,11 @@ def update_library_collection_items(
144144
# Parse the block_family from the key to use as namespace.
145145
block_type = BlockTypeKey.from_string(str(opaque_key))
146146
try:
147-
component = content_api.get_component_by_key(
147+
component = content_api.get_component_by_code(
148148
content_library.learning_package_id,
149149
namespace=block_type.block_family,
150150
type_name=opaque_key.block_type,
151-
local_key=opaque_key.block_id,
151+
component_code=opaque_key.block_id,
152152
)
153153
except Component.DoesNotExist as exc:
154154
raise ContentLibraryBlockNotFound(opaque_key) from exc

openedx/core/djangoapps/content_libraries/api/libraries.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -718,7 +718,7 @@ def library_component_usage_key(
718718
return LibraryUsageLocatorV2( # type: ignore[abstract]
719719
library_key,
720720
block_type=component.component_type.name,
721-
usage_id=component.local_key,
721+
usage_id=component.component_code,
722722
)
723723

724724

openedx/core/djangoapps/content_libraries/library_context.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ def block_exists(self, usage_key: LibraryUsageLocatorV2):
9595
if learning_package is None:
9696
return False
9797

98-
return content_api.component_exists_by_key(
98+
return content_api.component_exists_by_code(
9999
learning_package.id,
100100
namespace='xblock.v1',
101101
type_name=usage_key.block_type,
102-
local_key=usage_key.block_id,
102+
component_code=usage_key.block_id,
103103
)
104104

105105
def send_block_updated_event(self, usage_key: UsageKeyV2):

openedx/core/djangoapps/xblock/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,11 +202,11 @@ def get_component_from_usage_key(usage_key: UsageKeyV2) -> Component:
202202
learning_package = content_api.get_learning_package_by_ref(
203203
str(usage_key.context_key)
204204
)
205-
return content_api.get_component_by_key(
205+
return content_api.get_component_by_code(
206206
learning_package.id,
207207
namespace='xblock.v1',
208208
type_name=usage_key.block_type,
209-
local_key=usage_key.block_id,
209+
component_code=usage_key.block_id,
210210
)
211211

212212

openedx/core/djangoapps/xblock/runtime/openedx_content_runtime.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -328,11 +328,11 @@ def _get_component_from_usage_key(self, usage_key):
328328
"""
329329
learning_package = content_api.get_learning_package_by_ref(str(usage_key.lib_key))
330330
try:
331-
component = content_api.get_component_by_key(
331+
component = content_api.get_component_by_code(
332332
learning_package.id,
333333
namespace='xblock.v1',
334334
type_name=usage_key.block_type,
335-
local_key=usage_key.block_id,
335+
component_code=usage_key.block_id,
336336
)
337337
except ObjectDoesNotExist as exc:
338338
raise NoSuchUsage(usage_key) from exc

0 commit comments

Comments
 (0)