mitodl / micromasters

Portal for learners and course teams to access MITx Micromasters® programs
https://mm.mit.edu
BSD 3-Clause "New" or "Revised" License
29 stars 17 forks source link

FreezeGradeFailedException: Impossible to refresh the edX cache for user "Tara" in course course-v1:MITxT+14.740x+1T2023 #5344

Closed sentry-io[bot] closed 1 year ago

sentry-io[bot] commented 1 year ago

It looks like this error is leading to the user getting a 500 on their dashboard, as described in https://odl.zendesk.com/agent/tickets/211502

Sentry Issue: MICROMASTERS-8B2

TypeError: an integer is required (got type NoneType)
  File "backends/utils.py", line 45, in refresh_user_token
    last_update = datetime.fromtimestamp(user_social.extra_data.get('updated_at'), tz=pytz.UTC)

HTTPError: 400 Client Error: Bad Request for url: https://courses.mitxonline.mit.edu/oauth2/access_token/
(1 additional frame(s) were not displayed)
...
  File "backends/utils.py", line 26, in _send_refresh_request
    user_social.refresh_token(strategy)
  File "backends/base.py", line 144, in refresh_token
    response = super().refresh_token(token, *args, **kwargs)

InvalidCredentialStored: Received a 400 status code from the OAUTH server
  File "grades/api.py", line 166, in freeze_user_final_grade
    CachedEdxDataApi.update_all_cached_grade_data(user, course_run.courseware_backend)
  File "dashboard/api_edx_cache.py", line 375, in update_all_cached_grade_data
    utils.refresh_user_token(user_social)
  File "backends/utils.py", line 48, in refresh_user_token
    _send_refresh_request(user_social)
  File "backends/utils.py", line 29, in _send_refresh_request
    raise InvalidCredentialStored(

FreezeGradeFailedException: Impossible to refresh the edX cache for user "Tara" in course course-v1:MITxT+14.740x+1T2023
(3 additional frame(s) were not displayed)
...
  File "dashboard/api.py", line 219, in get_info_for_program
    get_info_for_course(course, mmtrack)
  File "dashboard/api.py", line 284, in get_info_for_course
    run_statuses = [get_status_for_courserun(course_run, mmtrack)
  File "dashboard/api.py", line 284, in <listcomp>
    run_statuses = [get_status_for_courserun(course_run, mmtrack)
  File "dashboard/api.py", line 422, in get_status_for_courserun
    api.freeze_user_final_grade(mmtrack.user, course_run, raise_on_exception=True)
  File "grades/api.py", line 178, in freeze_user_final_grade
    raise FreezeGradeFailedException(

An exception was intercepted by custom_exception_handler
pdpinch commented 1 year ago

I fixed this for two users with bad oauth tokens.

If this crops up again, see https://github.com/mitodl/hq/issues/2118 for instructions on how to fix it manually.

to fix this permanently, we may need to take a look at the code that refreshes oauth tokens for mitxonline.