From 612f32ff6355fa48f5af2c8fae50503706b70dc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=B4mulo=20Penido?= Date: Tue, 16 Apr 2024 19:26:00 -0300 Subject: [PATCH] fix: error in library crash reindex ```File"/openedx/edx-platform/openedx/core/djangoapps/content_libraries/api.py",line 617, in get_library_componentslearning_package.id,AttributeError: 'NoneType' object has no attribute'id'``` --- openedx/core/djangoapps/content/search/api.py | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/openedx/core/djangoapps/content/search/api.py b/openedx/core/djangoapps/content/search/api.py index 9d3ef1e30f26..3e1e12dcdfc8 100644 --- a/openedx/core/djangoapps/content/search/api.py +++ b/openedx/core/djangoapps/content/search/api.py @@ -316,19 +316,23 @@ def rebuild_index(status_cb: Callable[[str], None] | None = None) -> None: status_cb("Indexing libraries...") for lib_key in lib_keys: status_cb(f"{num_contexts_done + 1}/{num_contexts}. Now indexing library {lib_key}") - docs = [] - for component in lib_api.get_library_components(lib_key): - metadata = lib_api.LibraryXBlockMetadata.from_component(lib_key, component) - doc = {} - doc.update(searchable_doc_for_library_block(metadata)) - doc.update(searchable_doc_tags(metadata.usage_key)) - docs.append(doc) - - num_blocks_done += 1 - if docs: - # Add all the docs in this library at once (usually faster than adding one at a time): - _wait_for_meili_task(client.index(temp_index_name).add_documents(docs)) - num_contexts_done += 1 + try: + docs = [] + for component in lib_api.get_library_components(lib_key): + metadata = lib_api.LibraryXBlockMetadata.from_component(lib_key, component) + doc = {} + doc.update(searchable_doc_for_library_block(metadata)) + doc.update(searchable_doc_tags(metadata.usage_key)) + docs.append(doc) + + num_blocks_done += 1 + if docs: + # Add all the docs in this library at once (usually faster than adding one at a time): + _wait_for_meili_task(client.index(temp_index_name).add_documents(docs)) + except Exception as err: # pylint: disable=broad-except + status_cb(f"Error indexing library {lib_key}: {err}") + finally: + num_contexts_done += 1 ############## Courses ############## status_cb("Indexing courses...")