Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[sumac] fix: allow non-Elasticsearch search engines when reindexing courses [FC-0062] #35793

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading