Skip to content

Commit

Permalink
fix: allow non-Elasticsearch search engines when reindexing courses […
Browse files Browse the repository at this point in the history
…FC-0062] (openedx#35743)

(cherry picked from commit 689feba)
  • Loading branch information
pomegranited committed Nov 7, 2024
1 parent 8616aa5 commit 1bed8dc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
3 changes: 2 additions & 1 deletion cms/djangoapps/contentstore/courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,8 @@ def prepare_item_index(item, skip_index=False, groups_usage_info=None):
# Now index the content
for item in structure.get_children():
prepare_item_index(item, groups_usage_info=groups_usage_info)
searcher.index(items_index, request_timeout=timeout)
if items_index:
searcher.index(items_index, request_timeout=timeout)
cls.remove_deleted_items(searcher, structure_key, indexed_items)
except Exception as err: # pylint: disable=broad-except
# broad exception so that index operation does not prevent the rest of the application from working
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,14 +97,16 @@ def handle(self, *args, **options): # pylint: disable=too-many-statements
logging.exception('Search Engine error - %s', exc)
return

index_exists = searcher._es.indices.exists(index=index_name) # pylint: disable=protected-access
# Legacy Elasticsearch engine
if hasattr(searcher, '_es'): # pylint: disable=protected-access
index_exists = searcher._es.indices.exists(index=index_name) # pylint: disable=protected-access

index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access
index=index_name,
) if index_exists else {}
index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access
index=index_name,
) if index_exists else {}

if index_exists and index_mapping:
return
if index_exists and index_mapping:
return

# if reindexing is done during devstack setup step, don't prompt the user
if setup_option or query_yes_no(self.CONFIRMATION_PROMPT, default="no"):
Expand Down
5 changes: 5 additions & 0 deletions cms/djangoapps/contentstore/tests/test_courseware_index.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,6 +504,11 @@ def test_delete_course_from_search_index_after_course_deletion(self):
""" Test for removing course from CourseAboutSearchIndexer """
self._test_delete_course_from_search_index_after_course_deletion(self.store)

def test_empty_course(self):
empty_course = CourseFactory.create(modulestore=self.store, start=datetime(2015, 3, 1, tzinfo=UTC))
added_to_index = CoursewareSearchIndexer.do_course_reindex(self.store, empty_course.id)
assert added_to_index == 0


@patch('django.conf.settings.SEARCH_ENGINE', 'search.tests.utils.ForceRefreshElasticSearchEngine')
@ddt.ddt
Expand Down

0 comments on commit 1bed8dc

Please sign in to comment.