Skip to content

Commit

Permalink
Merge pull request #35097 from openedx/bbeggs/ENT-9187
Browse files Browse the repository at this point in the history
feat: check for session existance before cache access. ENT-9187.
  • Loading branch information
macdiesel authored Jul 9, 2024
2 parents 67a1401 + 7568e91 commit 96da990
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
7 changes: 6 additions & 1 deletion openedx/features/enterprise_support/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,13 @@ def enterprise_customer_from_session(request):
"""
Retrieve enterprise_customer data from the request's session,
returning a ``__CACHE_MISS__`` if absent.
Now checks for session existence before attempting to access it.
"""
return request.session.get(ENTERPRISE_CUSTOMER_KEY_NAME, _CACHE_MISS)
if not request or not hasattr(request, 'session'):
return _CACHE_MISS
else:
return request.session.get(ENTERPRISE_CUSTOMER_KEY_NAME, _CACHE_MISS)


def enterprise_customer_uuid_from_session(request):
Expand Down
5 changes: 5 additions & 0 deletions openedx/features/enterprise_support/tests/test_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
data_sharing_consent_required,
enterprise_customer_for_request,
enterprise_customer_from_api,
enterprise_customer_from_session,
enterprise_customer_from_session_or_learner_data,
enterprise_customer_uuid_for_request,
enterprise_enabled,
Expand Down Expand Up @@ -1331,6 +1332,10 @@ def test_enterprise_customer_from_session(self):
# verify that existing session value should not be updated for un-authenticate user
assert mock_request.session[ENTERPRISE_CUSTOMER_KEY_NAME] == enterprise_customer

@ddt.data(None, object())
def test_enterprise_customer_from_session_no_session_CACHE_MISS(self, request):
assert enterprise_customer_from_session(request) == _CACHE_MISS

def test_get_consent_notification_data_no_overrides(self):
enterprise_customer = {
'name': 'abc',
Expand Down

0 comments on commit 96da990

Please sign in to comment.