From 4a9f88b3c1154ac287b5e77f8428c00b40def248 Mon Sep 17 00:00:00 2001 From: Emma Green Date: Wed, 13 May 2020 16:03:26 -0400 Subject: [PATCH] not sure why we are getting errors here, but they shouldn't stop people checking out --- openedx/features/discounts/views.py | 19 +++++++++++++------ 1 file changed, 13 insertions(+), 6 deletions(-) diff --git a/openedx/features/discounts/views.py b/openedx/features/discounts/views.py index 35a2387717..7946276c7a 100644 --- a/openedx/features/discounts/views.py +++ b/openedx/features/discounts/views.py @@ -5,6 +5,8 @@ The Discount API Views should return information about discounts that apply to t # -*- coding: utf-8 -*- +import logging + from django.contrib.auth.models import User from django.utils.decorators import method_decorator from edx_rest_framework_extensions.auth.jwt.authentication import JwtAuthentication @@ -24,6 +26,8 @@ from openedx.core.lib.api.view_utils import DeveloperErrorViewMixin from .applicability import can_receive_discount, discount_percentage, REV1008_EXPERIMENT_ID +log = logging.getLogger(__name__) + class CourseUserDiscount(DeveloperErrorViewMixin, APIView): """ @@ -77,12 +81,15 @@ class CourseUserDiscount(DeveloperErrorViewMixin, APIView): payload = {'discount_applicable': discount_applicable, 'discount_percent': discount_percent} # Record whether the last basket loaded for this course had a discount - ExperimentData.objects.update_or_create( - user=request.user, - experiment_id=REV1008_EXPERIMENT_ID, - key='discount_' + str(course), - value=discount_applicable - ) + try: + ExperimentData.objects.update_or_create( + user=request.user, + experiment_id=REV1008_EXPERIMENT_ID, + key='discount_' + str(course), + value=discount_applicable + ) + except Exception as e: # pylint: disable=broad-except + log.exception(str(e)) return Response({ 'discount_applicable': discount_applicable,