mitodl/micromasters

Course.MultipleObjectsReturned: get() returned more than one Course -- it returned 8!

Closed this issue · 2 comments

Sentry Issue: MICROMASTERS-64P

Course.MultipleObjectsReturned: get() returned more than one Course -- it returned 8!
(5 additional frame(s) were not displayed)
...
  File "dashboard/api.py", line 274, in <listcomp>
    run_statuses = [get_status_for_courserun(course_run, mmtrack)
  File "dashboard/api.py", line 399, in get_status_for_courserun
    if mmtrack.has_paid(course_run.edx_course_key):
  File "dashboard/utils.py", line 225, in has_paid
    course = Course.objects.get(courserun__edx_course_key=edx_course_key)
  File "django/db/models/manager.py", line 82, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "django/db/models/query.py", line 410, in get
    raise self.model.MultipleObjectsReturned(

An exception was intercepted by custom_exception_handler

We had multiple course runs with None/empty edX course keys and when the code would hit this line with an empty edX course key to look it would break.

I think we need to create a PR to fix this, I confirmed with @pdpinch that a course run with no edx course key will not have a paid status in general.

Closed via #5238