From a730f811325fc0fbf06a51ca6ab6a3db5cb91f4f Mon Sep 17 00:00:00 2001 From: Waqas Khalid Date: Mon, 16 Feb 2015 15:29:34 +0500 Subject: [PATCH] Missing discussion blackout throwing exception When the list is empty in discussion blackout on studio side it causes the exception on lms side when we try to access the discussion. We were expecting the values and try to parse it in two values start and end date whereas parsing empty values to two values causing the exception. Now values will be parse when value exists. Empty value will be ignored. TNL-1390 --- cms/djangoapps/contentstore/tests/tests.py | 4 ++++ common/lib/xmodule/xmodule/course_module.py | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/cms/djangoapps/contentstore/tests/tests.py b/cms/djangoapps/contentstore/tests/tests.py index a3e4548465..350ef47f17 100644 --- a/cms/djangoapps/contentstore/tests/tests.py +++ b/cms/djangoapps/contentstore/tests/tests.py @@ -319,6 +319,10 @@ class ForumTestCase(CourseTestCase): self.course.discussion_blackouts = [(t.isoformat(), t2.isoformat()) for t, t2 in times2] self.assertFalse(self.course.forum_posts_allowed) + # test if user gives empty blackout date it should return true for forum_posts_allowed + self.course.discussion_blackouts = [[]] + self.assertTrue(self.course.forum_posts_allowed) + @ddt class CourseKeyVerificationTestCase(CourseTestCase): diff --git a/common/lib/xmodule/xmodule/course_module.py b/common/lib/xmodule/xmodule/course_module.py index cb91fe4b6b..405eb07980 100644 --- a/common/lib/xmodule/xmodule/course_module.py +++ b/common/lib/xmodule/xmodule/course_module.py @@ -1294,13 +1294,13 @@ class CourseDescriptor(CourseFields, SequenceDescriptor): blackout_periods = [(date_proxy.from_json(start), date_proxy.from_json(end)) for start, end - in self.discussion_blackouts] + in filter(None, self.discussion_blackouts)] now = datetime.now(UTC()) for start, end in blackout_periods: if start <= now <= end: return False except: - log.exception("Error parsing discussion_blackouts for course {0}".format(self.id)) + log.exception("Error parsing discussion_blackouts %s for course %s", self.discussion_blackouts, self.id) return True