fix: errors with anonymous user (#29042)

There are several errors that appear in monitoring when calls
are made with an anonymous user. This resolves one (or more).
This commit is contained in:
Robert Raposa
2021-10-28 10:05:48 -04:00
committed by GitHub
parent af7fb754ab
commit b6a943c392
2 changed files with 8 additions and 1 deletions

View File

@@ -69,6 +69,9 @@ def get_course_tag(user, course_id, key):
Returns:
string value, or None if there is no value saved
"""
if user.is_anonymous:
return None
if BulkCourseTags.is_prefetched(course_id):
try:
return BulkCourseTags.get_course_tag(user.id, course_id, key)

View File

@@ -2,7 +2,7 @@
Test the user course tag API.
"""
from django.contrib.auth.models import AnonymousUser
from django.test import TestCase
from opaque_keys.edx.locator import CourseLocator
@@ -21,6 +21,10 @@ class TestCourseTagAPI(TestCase):
self.course_id = CourseLocator('test_org', 'test_course_number', 'test_run')
self.test_key = 'test_key'
def test_get_course_tag_for_anonymous_user(self):
tag = course_tag_api.get_course_tag(AnonymousUser(), self.course_id, self.test_key)
assert tag is None
def test_get_set_course_tag(self):
# get a tag that doesn't exist
tag = course_tag_api.get_course_tag(self.user, self.course_id, self.test_key)