From 65d0c11591d2b338b7946e08f6ba484beffe1a08 Mon Sep 17 00:00:00 2001 From: Diana Huang Date: Mon, 16 Nov 2020 13:17:38 -0500 Subject: [PATCH] Catch individual errors instead of failing the entire job for course indexing. --- .../contentstore/management/commands/reindex_course.py | 5 ++++- .../management/commands/tests/test_reindex_courses.py | 8 -------- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/cms/djangoapps/contentstore/management/commands/reindex_course.py b/cms/djangoapps/contentstore/management/commands/reindex_course.py index 9d5ccf4291..c84af51ade 100644 --- a/cms/djangoapps/contentstore/management/commands/reindex_course.py +++ b/cms/djangoapps/contentstore/management/commands/reindex_course.py @@ -101,4 +101,7 @@ class Command(BaseCommand): course_keys = list(map(self._parse_course_key, course_ids)) for course_key in course_keys: - CoursewareSearchIndexer.do_course_reindex(store, course_key) + try: + CoursewareSearchIndexer.do_course_reindex(store, course_key) + except Exception as exc: + logging.exception('Error indexing course %s due to the error: %s', course_key, exc) diff --git a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py index fc645df8d9..7f8a7a860d 100644 --- a/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py +++ b/cms/djangoapps/contentstore/management/commands/tests/test_reindex_courses.py @@ -119,11 +119,3 @@ class TestReindexCourse(ModuleStoreTestCase): patched_yes_no.assert_called_once_with(ReindexCommand.CONFIRMATION_PROMPT, default='no') patched_index.assert_not_called() - - def test_fail_fast_if_reindex_fails(self): - """ Test that fails on first reindexing exception """ - with mock.patch(self.REINDEX_PATH_LOCATION) as patched_index: - patched_index.side_effect = SearchIndexingError("message", []) - - with self.assertRaises(SearchIndexingError): - call_command('reindex_course', text_type(self.second_course.id))