Skip to content

Commit 689feba

Browse files
authored
fix: allow non-Elasticsearch search engines when reindexing courses [FC-0062] (openedx#35743)
1 parent 952ba95 commit 689feba

File tree

3 files changed

+15
-7
lines changed

3 files changed

+15
-7
lines changed

cms/djangoapps/contentstore/courseware_index.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -256,7 +256,8 @@ def prepare_item_index(item, skip_index=False, groups_usage_info=None):
256256
# Now index the content
257257
for item in structure.get_children():
258258
prepare_item_index(item, groups_usage_info=groups_usage_info)
259-
searcher.index(items_index, request_timeout=timeout)
259+
if items_index:
260+
searcher.index(items_index, request_timeout=timeout)
260261
cls.remove_deleted_items(searcher, structure_key, indexed_items)
261262
except Exception as err: # pylint: disable=broad-except
262263
# broad exception so that index operation does not prevent the rest of the application from working

cms/djangoapps/contentstore/management/commands/reindex_course.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,16 @@ def handle(self, *args, **options): # pylint: disable=too-many-statements
9797
logging.exception('Search Engine error - %s', exc)
9898
return
9999

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

102-
index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access
103-
index=index_name,
104-
) if index_exists else {}
104+
index_mapping = searcher._es.indices.get_mapping( # pylint: disable=protected-access
105+
index=index_name,
106+
) if index_exists else {}
105107

106-
if index_exists and index_mapping:
107-
return
108+
if index_exists and index_mapping:
109+
return
108110

109111
# if reindexing is done during devstack setup step, don't prompt the user
110112
if setup_option or query_yes_no(self.CONFIRMATION_PROMPT, default="no"):

cms/djangoapps/contentstore/tests/test_courseware_index.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -504,6 +504,11 @@ def test_delete_course_from_search_index_after_course_deletion(self):
504504
""" Test for removing course from CourseAboutSearchIndexer """
505505
self._test_delete_course_from_search_index_after_course_deletion(self.store)
506506

507+
def test_empty_course(self):
508+
empty_course = CourseFactory.create(modulestore=self.store, start=datetime(2015, 3, 1, tzinfo=UTC))
509+
added_to_index = CoursewareSearchIndexer.do_course_reindex(self.store, empty_course.id)
510+
assert added_to_index == 0
511+
507512

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

0 commit comments

Comments
 (0)