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:
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user