Skip to content

Commit

Permalink
fix: error in library crash reindex
Browse files Browse the repository at this point in the history
```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'```
  • Loading branch information
rpenido committed Apr 16, 2024
1 parent 3b6e475 commit 612f32f
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions openedx/core/djangoapps/content/search/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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...")
Expand Down

0 comments on commit 612f32f

Please sign in to comment.