Protection for when there is no CourseOverview data available.

This commit is contained in:
Albert St. Aubin
2018-03-29 07:10:58 -04:00
parent 5ac5d9d532
commit e8a3077bfa

View File

@@ -1,8 +1,12 @@
import logging
from django.utils import timezone
from course_modes.models import CourseMode
from openedx.core.djangoapps.content.course_overviews.models import CourseOverview
log = logging.getLogger("common.entitlements.utils")
def is_course_run_entitlement_fulfillable(course_run_key, entitlement, compare_date=timezone.now()):
"""
@@ -22,6 +26,13 @@ def is_course_run_entitlement_fulfillable(course_run_key, entitlement, compare_d
"""
course_overview = CourseOverview.get_from_id(course_run_key)
if not course_overview:
log.error(('There is no CourseOverview entry available for {course_run_id}, '
'course run cannot be applied to entitlement').format(
course_run_id=str(course_run_key)
))
return False
# Verify that the course is still running
run_start = course_overview.start
run_end = course_overview.end