diff --git a/openedx/features/enterprise_support/tests/test_utils.py b/openedx/features/enterprise_support/tests/test_utils.py index 4d4c1b57d3f9..670a60f21875 100644 --- a/openedx/features/enterprise_support/tests/test_utils.py +++ b/openedx/features/enterprise_support/tests/test_utils.py @@ -447,6 +447,13 @@ def test_get_enterprise_learner_portal_no_enterprise_user(self): portal = get_enterprise_learner_portal(request) assert portal is None + @override_waffle_flag(ENTERPRISE_HEADER_LINKS, True) + def test_get_enterprise_learner_portal_request_without_user(self): + request = mock.MagicMock(spec=[]) + request.session = {} + portal = get_enterprise_learner_portal(request) + assert portal is None + def test_get_enterprise_learner_generic_name_404_pages(self): request = mock.Mock(view_name='404') assert get_enterprise_learner_generic_name(request) is None diff --git a/openedx/features/enterprise_support/utils.py b/openedx/features/enterprise_support/utils.py index cc6402e60492..61f8343c4afb 100644 --- a/openedx/features/enterprise_support/utils.py +++ b/openedx/features/enterprise_support/utils.py @@ -328,7 +328,7 @@ def get_enterprise_learner_portal(request): # Prevent a circular import. from openedx.features.enterprise_support.api import enterprise_customer_uuid_for_request, enterprise_enabled - user = request.user + user = getattr(request, 'user', None) # Only cache this if a learner is authenticated (AnonymousUser exists and should not be tracked) learner_portal_session_key = 'enterprise_learner_portal'