From 93fd8cc14817f4fcf20b8aba2f59b9ca2f7639db Mon Sep 17 00:00:00 2001 From: Henrry Pulgarin <39854568+Henrrypg@users.noreply.github.com> Date: Wed, 30 Nov 2022 09:50:48 -0500 Subject: [PATCH] fix: prevent 500 error when course mode currency is not the same as the one configured in settings (#31312) This commit solves the http 500 error when course concurrency is setted different for PAID_COURSE_REGISTRATION_CURRENCY and course modes. --- common/djangoapps/course_modes/models.py | 5 ++++- common/djangoapps/course_modes/tests/test_models.py | 5 +++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/common/djangoapps/course_modes/models.py b/common/djangoapps/course_modes/models.py index 0b015a133c..1cb7161fe2 100644 --- a/common/djangoapps/course_modes/models.py +++ b/common/djangoapps/course_modes/models.py @@ -774,7 +774,10 @@ class CourseMode(models.Model): If there is no mode found, will return the price of DEFAULT_MODE, which is 0 """ modes = cls.modes_for_course(course_id) - return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower()) + return min( + (mode.min_price for mode in modes if mode.currency.lower() == currency.lower()), + default=0 + ) @classmethod def is_eligible_for_certificate(cls, mode_slug, status=None): diff --git a/common/djangoapps/course_modes/tests/test_models.py b/common/djangoapps/course_modes/tests/test_models.py index 267b0259e1..9ce9e95c8e 100644 --- a/common/djangoapps/course_modes/tests/test_models.py +++ b/common/djangoapps/course_modes/tests/test_models.py @@ -125,6 +125,11 @@ class CourseModeModelTest(TestCase): # no modes, should get 0 assert 0 == CourseMode.min_course_price_for_currency(self.course_key, 'usd') + # with mode with other currency, should get 0 + mode = Mode('audit', 'Audit', 30, '', 'eur', None, None, None, None) + self.create_mode(mode.slug, mode.name, mode.min_price, mode.suggested_prices, mode.currency) + assert 0 == CourseMode.min_course_price_for_currency(self.course_key, 'usd') + # create some modes mode1 = Mode('honor', 'Honor Code Certificate', 10, '', 'usd', None, None, None, None) mode2 = Mode('verified', 'Verified Certificate', 20, '', 'usd', None, None, None, None)