From e2e37154ce9d69e7e05175aa76571bf89f375ff4 Mon Sep 17 00:00:00 2001 From: Michael Terry Date: Thu, 9 Dec 2021 10:26:51 -0500 Subject: [PATCH] fix: add a couple guards for anonymous users This fixes a couple places (LastSeenCoursewareTimezone and UserCourseTag) where we were saving an entry for a user, but not making sure we ignored anonymous users. --- openedx/core/djangoapps/courseware_api/views.py | 3 +++ openedx/core/djangoapps/user_api/course_tag/api.py | 3 +++ 2 files changed, 6 insertions(+) diff --git a/openedx/core/djangoapps/courseware_api/views.py b/openedx/core/djangoapps/courseware_api/views.py index 1380c74962..d92d134860 100644 --- a/openedx/core/djangoapps/courseware_api/views.py +++ b/openedx/core/djangoapps/courseware_api/views.py @@ -498,6 +498,9 @@ class CoursewareInformation(RetrieveAPIView): The timezone in the user's account is frequently not set. This method sets a user's recent timezone that can be used as a fallback """ + if not user.id: + return + cache_key = 'browser_timezone_{}'.format(str(user.id)) browser_timezone = self.request.query_params.get('browser_timezone', None) cached_value = TieredCache.get_cached_response(cache_key) diff --git a/openedx/core/djangoapps/user_api/course_tag/api.py b/openedx/core/djangoapps/user_api/course_tag/api.py index a12c19905a..4222f91264 100644 --- a/openedx/core/djangoapps/user_api/course_tag/api.py +++ b/openedx/core/djangoapps/user_api/course_tag/api.py @@ -107,6 +107,9 @@ def set_course_tag(user, course_id, key, value): # simultaneous calls from many processes. Handle by retrying after # a short delay? + if not user.id: + return + record, _ = UserCourseTag.objects.get_or_create( user=user, course_id=course_id,