Skip to content

Commit f93cc26

Browse files
kdmccormickclaude
andcommitted
refactor: Rename Collection.key and update backup/restore for openedx-core 0.43.0
Renames all Collection APIs that took key/collection_key to use collection_code: create_collection, update_collection, delete_collection, restore_collection, add_to_collection, etc. Switches Collection.key attribute reads to .collection_code across tests, signal handlers, search indexers, and modulestore_migrator. Filters like target_collection__key become target_collection__collection_code. Also updates the library restore serializer to track the renamed lp_restored_data fields: archive_org_key -> archive_org_code, archive_slug -> archive_package_code, key -> package_ref, archive_lp_key -> archive_package_ref. The archive_org_code and archive_package_code fields now allow None, since openedx-core no longer raises ValueError when the archive_package_ref cannot be parsed as {prefix}:{org_code}:{package_code}. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 0135e83 commit f93cc26

18 files changed

Lines changed: 93 additions & 91 deletions

File tree

cms/djangoapps/contentstore/rest_api/v1/views/tests/test_home.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ def setUp(self):
274274
collection_key = "test-collection"
275275
content_api.create_collection(
276276
learning_package_id=learning_package.id,
277-
key=collection_key,
277+
collection_code=collection_key,
278278
title="Test Collection",
279279
created_by=self.user.id,
280280
)

cms/djangoapps/modulestore_migrator/api/read_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def get_migrations(
137137
if target_key:
138138
migrations = migrations.filter(target__key=str(target_key))
139139
if target_collection_slug:
140-
migrations = migrations.filter(target_collection__key=target_collection_slug)
140+
migrations = migrations.filter(target_collection__collection_code=target_collection_slug)
141141
if task_uuid:
142142
migrations = migrations.filter(task_status__uuid=task_uuid)
143143
if is_failed is not None:
@@ -176,9 +176,9 @@ def _migration(m: models.ModulestoreMigration) -> ModulestoreMigration:
176176
return ModulestoreMigration(
177177
pk=m.id,
178178
source_key=m.source.key,
179-
target_key=LibraryLocatorV2.from_string(m.target.key),
179+
target_key=LibraryLocatorV2.from_string(m.target.package_ref),
180180
target_title=m.target.title,
181-
target_collection_slug=(m.target_collection.key if m.target_collection else None),
181+
target_collection_slug=(m.target_collection.collection_code if m.target_collection else None),
182182
target_collection_title=(m.target_collection.title if m.target_collection else None),
183183
is_failed=m.is_failed,
184184
task_uuid=m.task_status.uuid,

cms/djangoapps/modulestore_migrator/tasks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def _populate_collection(user_id: int, migration: models.ModulestoreMigration) -
409409
if block_target_pks:
410410
content_api.add_to_collection(
411411
learning_package_id=migration.target.pk,
412-
key=migration.target_collection.key,
412+
collection_code=migration.target_collection.collection_code,
413413
entities_qset=PublishableEntity.objects.filter(id__in=block_target_pks),
414414
created_by=user_id,
415415
)

cms/djangoapps/modulestore_migrator/tests/test_api.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ def test_start_migration_to_library_with_collection(self):
232232
collection_key = "test-collection"
233233
content_api.create_collection(
234234
learning_package_id=self.learning_package.id,
235-
key=collection_key,
235+
collection_code=collection_key,
236236
title="Test Collection",
237237
created_by=user.id,
238238
)
@@ -249,7 +249,7 @@ def test_start_migration_to_library_with_collection(self):
249249
)
250250

251251
modulestoremigration = ModulestoreMigration.objects.get()
252-
assert modulestoremigration.target_collection.key == collection_key
252+
assert modulestoremigration.target_collection.collection_code == collection_key
253253

254254
def test_start_migration_to_library_with_strategy_skip(self):
255255
"""
@@ -487,19 +487,19 @@ def test_migration_api_for_various_scenarios(self):
487487
# Lib 2 has Collection C
488488
content_api.create_collection(
489489
learning_package_id=self.learning_package.id,
490-
key="test-collection-1a",
490+
collection_code="test-collection-1a",
491491
title="Test Collection A in Lib 1",
492492
created_by=user.id,
493493
)
494494
content_api.create_collection(
495495
learning_package_id=self.learning_package.id,
496-
key="test-collection-1b",
496+
collection_code="test-collection-1b",
497497
title="Test Collection B in Lib 1",
498498
created_by=user.id,
499499
)
500500
content_api.create_collection(
501501
learning_package_id=self.learning_package_2.id,
502-
key="test-collection-2c",
502+
collection_code="test-collection-2c",
503503
title="Test Collection C in Lib 2",
504504
created_by=user.id,
505505
)

openedx/core/djangoapps/content/search/api.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -499,7 +499,7 @@ def index_collection_batch(batch, num_done, library_key) -> int:
499499
docs = []
500500
for collection in batch:
501501
try:
502-
collection_key = lib_api.library_collection_locator(library_key, collection.key)
502+
collection_key = lib_api.library_collection_locator(library_key, collection.collection_code)
503503
doc = searchable_doc_for_collection(collection_key, collection=collection)
504504
doc.update(searchable_doc_tags(collection_key))
505505
docs.append(doc)
@@ -894,7 +894,7 @@ def upsert_content_library_index_docs(library_key: LibraryLocatorV2, full_index:
894894
docs.append(doc)
895895

896896
for collection in lib_api.get_library_collections(library_key):
897-
collection_key = lib_api.library_collection_locator(library_key, collection.key)
897+
collection_key = lib_api.library_collection_locator(library_key, collection.collection_code)
898898
doc = searchable_doc_for_collection(collection_key, collection=collection)
899899
docs.append(doc)
900900

openedx/core/djangoapps/content/search/documents.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class Fields:
3333
usage_key = "usage_key"
3434
type = "type" # DocType.course_block or DocType.library_block (see below)
3535
# The block_id part of the usage key for course or library blocks.
36-
# If it's a collection, the collection.key is stored here.
36+
# If it's a collection, the collection.collection_code is stored here.
3737
# Sometimes human-readable, sometimes a random hex ID
3838
# Is only unique within the given context_key.
3939
block_id = "block_id"
@@ -64,7 +64,7 @@ class Fields:
6464
tags_level2 = "level2"
6565
tags_level3 = "level3"
6666
# Collections (dictionary) that this object belongs to.
67-
# Similarly to tags above, we collect the collection.titles and collection.keys into hierarchical facets.
67+
# Similarly to tags above, we collect the collection.titles and collection.collection_codes into hierarchical facets.
6868
collections = "collections"
6969
collections_display_name = "display_name"
7070
collections_key = "key"
@@ -543,7 +543,7 @@ def searchable_doc_for_collection(
543543
pass
544544

545545
if collection:
546-
assert collection.key == collection_key.collection_id
546+
assert collection.collection_code == collection_key.collection_id
547547

548548
draft_num_children = content_api.filter_publishable_entities(
549549
collection.entities,
@@ -558,7 +558,7 @@ def searchable_doc_for_collection(
558558
Fields.context_key: str(collection_key.context_key),
559559
Fields.org: str(collection_key.org),
560560
Fields.usage_key: str(collection_key),
561-
Fields.block_id: collection.key,
561+
Fields.block_id: collection.collection_code,
562562
Fields.type: DocType.collection,
563563
Fields.display_name: collection.title,
564564
Fields.description: collection.description,

openedx/core/djangoapps/content/search/tests/test_api.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ def setUp(self) -> None:
192192
with freeze_time(self.created_date):
193193
self.collection = content_api.create_collection(
194194
learning_package_id=self.learning_package.id,
195-
key="MYCOL",
195+
collection_code="MYCOL",
196196
title="my_collection",
197197
created_by=None,
198198
description="my collection description"
@@ -202,7 +202,7 @@ def setUp(self) -> None:
202202
)
203203
self.collection_dict = {
204204
"id": "lib-collectionorg1libmycol-5b647617",
205-
"block_id": self.collection.key,
205+
"block_id": self.collection.collection_code,
206206
"usage_key": str(self.collection_key),
207207
"type": "collection",
208208
"display_name": "my_collection",
@@ -709,7 +709,7 @@ def test_index_library_block_and_collections(self, mock_meilisearch) -> None:
709709
for collection in (collection2, collection1):
710710
library_api.update_library_collection_items(
711711
self.library.key,
712-
collection_key=collection.key,
712+
collection_key=collection.collection_code,
713713
opaque_keys=[
714714
self.problem1.usage_key,
715715
],
@@ -891,7 +891,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
891891
with freeze_time(updated_date):
892892
library_api.update_library_collection_items(
893893
self.library.key,
894-
collection_key=self.collection.key,
894+
collection_key=self.collection.collection_code,
895895
opaque_keys=[
896896
self.problem1.usage_key,
897897
self.unit.container_key
@@ -905,14 +905,14 @@ def test_delete_collection(self, mock_meilisearch) -> None:
905905
"id": self.doc_problem1["id"],
906906
"collections": {
907907
"display_name": [self.collection.title],
908-
"key": [self.collection.key],
908+
"key": [self.collection.collection_code],
909909
},
910910
}
911911
doc_unit_with_collection = {
912912
"id": self.unit_dict["id"],
913913
"collections": {
914914
"display_name": [self.collection.title],
915-
"key": [self.collection.key],
915+
"key": [self.collection.collection_code],
916916
},
917917
}
918918

@@ -931,7 +931,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
931931
# Soft-delete the collection
932932
content_api.delete_collection(
933933
self.collection.learning_package_id,
934-
self.collection.key,
934+
self.collection.collection_code,
935935
)
936936

937937
doc_problem_without_collection = {
@@ -966,7 +966,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
966966
with freeze_time(restored_date):
967967
content_api.restore_collection(
968968
self.collection.learning_package_id,
969-
self.collection.key,
969+
self.collection.collection_code,
970970
)
971971

972972
doc_collection = copy.deepcopy(self.collection_dict)
@@ -988,7 +988,7 @@ def test_delete_collection(self, mock_meilisearch) -> None:
988988
# Hard-delete the collection
989989
content_api.delete_collection(
990990
self.collection.learning_package_id,
991-
self.collection.key,
991+
self.collection.collection_code,
992992
hard_delete=True,
993993
)
994994

openedx/core/djangoapps/content/search/tests/test_documents.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ def test_collection_with_library(self):
492492

493493
assert doc == {
494494
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
495-
"block_id": self.collection.key,
495+
"block_id": self.collection.collection_code,
496496
"usage_key": str(self.collection_key),
497497
"type": "collection",
498498
"org": "edX",
@@ -521,7 +521,7 @@ def test_collection_with_published_library(self):
521521

522522
assert doc == {
523523
"id": "lib-collectionedx2012_falltoy_collection-d1d907a4",
524-
"block_id": self.collection.key,
524+
"block_id": self.collection.collection_code,
525525
"usage_key": str(self.collection_key),
526526
"type": "collection",
527527
"org": "edX",

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -743,7 +743,7 @@ def send_block_deleted_signal():
743743
library_collection=LibraryCollectionData(
744744
collection_key=library_collection_locator(
745745
library_key=library_key,
746-
collection_key=collection.key,
746+
collection_key=collection.collection_code,
747747
),
748748
background=True,
749749
)
@@ -809,7 +809,7 @@ def restore_library_block(usage_key: LibraryUsageLocatorV2, user_id: int | None
809809
library_collection=LibraryCollectionData(
810810
collection_key=library_collection_locator(
811811
library_key=library_key,
812-
collection_key=collection.key,
812+
collection_key=collection.collection_code,
813813
),
814814
background=True,
815815
)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def create_library_collection(
5454
try:
5555
collection = content_api.create_collection(
5656
learning_package_id=content_library.learning_package_id,
57-
key=collection_key,
57+
collection_code=collection_key,
5858
title=title,
5959
description=description,
6060
created_by=created_by,
@@ -86,7 +86,7 @@ def update_library_collection(
8686
try:
8787
collection = content_api.update_collection(
8888
learning_package_id=content_library.learning_package_id,
89-
key=collection_key,
89+
collection_code=collection_key,
9090
title=title,
9191
description=description,
9292
)
@@ -214,7 +214,7 @@ def set_library_item_collections(
214214

215215
# Note: Component.entity_ref matches its PublishableEntity.entity_ref
216216
collection_qs = content_api.get_collections(content_library.learning_package_id).filter(
217-
key__in=collection_keys
217+
collection_code__in=collection_keys
218218
)
219219

220220
affected_collections = content_api.set_collections(
@@ -232,7 +232,7 @@ def set_library_item_collections(
232232
library_collection=LibraryCollectionData(
233233
collection_key=library_collection_locator(
234234
library_key=library_key,
235-
collection_key=collection.key,
235+
collection_key=collection.collection_code,
236236
),
237237
background=True,
238238
)

0 commit comments

Comments
 (0)