/about gives 500 error: `min_course_price_for_currency` is the issue

356 views
Skip to first unread message

Samuel Marks

unread,
Feb 20, 2018, 5:21:14 PM2/20/18
to General Open edX discussion
Is this a bug I should report, or have I misconfigured?

Feb 20 22:12:35 OpenEdX4 [service_variant=lms][django.request][env:sandbox] ERROR [OpenEdX4  3812] [base.py:256] - Internal Server Error: /courses/course-v1:mycourseid/about
Traceback (most recent call last):
 
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/core/handlers/base.py", line 132, in get_response
    response
= wrapped_callback(request, *callback_args, **callback_kwargs)
 
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner
   
return func(*args, **kwargs)
 
File "/edx/app/edxapp/venvs/edxapp/local/lib/python2.7/site-packages/django/utils/decorators.py", line 110, in _wrapped_view
    response
= view_func(request, *args, **kwargs)
 
File "/edx/app/edxapp/edx-platform/common/djangoapps/util/views.py", line 49, in inner
    response
= view_func(request, *args, **kwargs)
 
File "/edx/app/edxapp/edx-platform/common/djangoapps/util/cache.py", line 83, in wrapper
   
return view_func(request, *args, **kwargs)
 
File "/edx/app/edxapp/edx-platform/lms/djangoapps/courseware/views/views.py", line 762, in course_about
    registration_price
, course_price = get_course_prices(course)
 
File "/edx/app/edxapp/edx-platform/lms/djangoapps/courseware/views/views.py", line 607, in get_course_prices
    settings
.PAID_COURSE_REGISTRATION_CURRENCY[0]
 
File "/edx/app/edxapp/edx-platform/common/djangoapps/course_modes/models.py", line 649, in min_course_price_for_currency
   
return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower())
ValueError: min() arg is an empty sequence

In the meantime, I've rewritten mine to:
   
@classmethod
   
def min_course_price_for_currency(cls, course_id, currency):
       
"""
        Returns the minimum price of the course in the appropriate currency over all the course's
        non-expired modes.
        If there is no mode found, will return the price of DEFAULT_MODE, which is 0
        """

        modes
= cls.modes_for_course(course_id)
       
if modes:
           
return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower())
       
return cls.DEFAULT_MODE

(was: https://github.com/edx/edx-platform/blob/25130ae3c8333e5353ab88860c76619ebb9098f9/common/djangoapps/course_modes/models.py#L674 )

Samuel Marks

unread,
Feb 20, 2018, 5:35:07 PM2/20/18
to General Open edX discussion
Actual fix, I ended up just copying min_course_price_for_verified_for_currency:

    @classmethod
   
def min_course_price_for_currency(cls, course_id, currency):
       
"""
        Returns the minimum price of the course in the appropriate currency over all the course's
        non-expired modes.
        If there is no mode found, will return the price of DEFAULT_MODE, which is 0
        """

        modes
= cls.modes_for_course(course_id)

       
for mode in modes:
           
if mode.currency.lower() == currency.lower() and mode.min_price:
               
return mode.min_price
       
return 0

Isanka Wijerathne

unread,
Jul 27, 2020, 8:22:50 AM7/27/20
to General Open edX discussion
You can add a default value to return

For Python 2 versions

return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower() or [0])

For Python 3 versions

return min(mode.min_price for mode in modes if mode.currency.lower() == currency.lower(),  default=0)

Samuel Marks

unread,
Aug 6, 2020, 8:26:51 AM8/6/20
to edx-...@googlegroups.com
Good point, but keep in mind I asked the question 2 years ago. For an newer question of mine, please see https://discuss.openedx.org/t/migrate-from-eucalyptus-to-juniper/2881

=]

--
***Please note! This Google Group has been deprecated - visit https://discuss.openedx.org/
---
You received this message because you are subscribed to a topic in the Google Groups "General Open edX discussion" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/edx-code/sB_ZPfqee2U/unsubscribe.
To unsubscribe from this group and all its topics, send an email to edx-code+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/edx-code/121602ba-6bb1-4b7a-ad8a-0edbbdd7e9dfo%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages