From 93f436d27da9d6e265494b6a75c1dd3385ad9fe4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Tue, 8 Oct 2024 10:48:27 -0300 Subject: [PATCH] fix: circuvent meilisearch bug with empty objects --- .../core/djangoapps/content/search/documents.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 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)