Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 21 additions & 9 deletions openedx/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -838,15 +838,27 @@ def _refresh_edx_api_auth(auth):
updated OpenEdxApiAuth
"""
# Note: this is subject to thundering herd problems, we should address this at some point
return _create_tokens_and_update_auth(
auth,
dict( # noqa: C408
refresh_token=auth.refresh_token,
grant_type="refresh_token",
client_id=settings.OPENEDX_API_CLIENT_ID,
client_secret=settings.OPENEDX_API_CLIENT_SECRET,
),
)
try:
return _create_tokens_and_update_auth(
auth,
dict( # noqa: C408
refresh_token=auth.refresh_token,
grant_type="refresh_token",
client_id=settings.OPENEDX_API_CLIENT_ID,
client_secret=settings.OPENEDX_API_CLIENT_SECRET,
),
)
except requests.exceptions.HTTPError as exc:
if exc.response is not None and exc.response.status_code == 400: # noqa: PLR2004
log.warning(
"Refresh token rejected with 400 for user %s; clearing tokens and attempting full re-authorization.",
auth.user,
)
auth.refresh_token = None
auth.access_token = None
auth.save(update_fields=["refresh_token", "access_token"])
return create_edx_auth_token(auth.user)
raise


def get_edx_api_client(user, ttl_in_seconds=OPENEDX_AUTH_DEFAULT_TTL_IN_SECONDS):
Expand Down
9 changes: 8 additions & 1 deletion openedx/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,14 @@ def update_edx_user_profile(user_id):
Task to update the edX user profile. This doesn't change the name or email.
"""
user = User.objects.get(id=user_id)
api.update_edx_user_profile(user)
try:
api.update_edx_user_profile(user)
except Exception:
log.exception(
"Failed to update Open edX user profile for user %s (id=%s); skipping.",
user,
user_id,
)


@app.task(
Expand Down
Loading