From 758334f3083c5ec3b26479f4765f3b49328bd4c9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Thu, 10 Oct 2024 11:25:16 -0300 Subject: [PATCH] fix: circuvent meilisearch bug --- .../core/djangoapps/content/search/documents.py | 15 ++++++++------- .../djangoapps/content/search/tests/test_api.py | 8 ++++---- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/openedx/core/djangoapps/content/search/documents.py b/openedx/core/djangoapps/content/search/documents.py index eabeab9654ca..f520cd14e40f 100644 --- a/openedx/core/djangoapps/content/search/documents.py +++ b/openedx/core/djangoapps/content/search/documents.py @@ -267,6 +267,13 @@ def _collections_for_content_object(object_id: UsageKey | LearningContextKey) -> } """ + result = { + Fields.collections: { + Fields.collections_display_name: [], + Fields.collections_key: [], + } + } + # Gather the collections associated with this object collections = None try: @@ -279,14 +286,8 @@ def _collections_for_content_object(object_id: UsageKey | LearningContextKey) -> log.warning(f"No component found for {object_id}") if not collections: - return {Fields.collections: {}} + return result - result = { - Fields.collections: { - Fields.collections_display_name: [], - Fields.collections_key: [], - } - } for collection in collections: result[Fields.collections][Fields.collections_display_name].append(collection.title) result[Fields.collections][Fields.collections_key].append(collection.key) diff --git a/openedx/core/djangoapps/content/search/tests/test_api.py b/openedx/core/djangoapps/content/search/tests/test_api.py index 4c6227af309f..c89d84490e96 100644 --- a/openedx/core/djangoapps/content/search/tests/test_api.py +++ b/openedx/core/djangoapps/content/search/tests/test_api.py @@ -219,10 +219,10 @@ def test_reindex_meilisearch(self, mock_meilisearch): doc_vertical["tags"] = {} doc_problem1 = copy.deepcopy(self.doc_problem1) doc_problem1["tags"] = {} - doc_problem1["collections"] = {} + doc_problem1["collections"] = {'display_name': [], 'key': []} doc_problem2 = copy.deepcopy(self.doc_problem2) doc_problem2["tags"] = {} - doc_problem2["collections"] = {} + doc_problem2["collections"] = {'display_name': [], 'key': []} doc_collection = copy.deepcopy(self.collection_dict) doc_collection["tags"] = {} @@ -263,7 +263,7 @@ def test_reindex_meilisearch_library_block_error(self, mock_meilisearch): doc_vertical["tags"] = {} doc_problem2 = copy.deepcopy(self.doc_problem2) doc_problem2["tags"] = {} - doc_problem2["collections"] = {} + doc_problem2["collections"] = {'display_name': [], 'key': []} orig_from_component = library_api.LibraryXBlockMetadata.from_component @@ -662,7 +662,7 @@ def test_delete_collection(self, mock_meilisearch): doc_problem_without_collection = { "id": self.doc_problem1["id"], - "collections": {}, + "collections": {'display_name': [], 'key': []}, } # Should delete the collection document