diff --git a/common/djangoapps/embargo/middleware.py b/common/djangoapps/embargo/middleware.py index fe1727da17..e7c199cc6e 100644 --- a/common/djangoapps/embargo/middleware.py +++ b/common/djangoapps/embargo/middleware.py @@ -166,7 +166,7 @@ class EmbargoMiddleware(object): profile_country = cache.get(cache_key) if profile_country is None: profile = getattr(user, 'profile', None) - if profile is not None: + if profile is not None and profile.country is not None: profile_country = profile.country.code.upper() else: profile_country = "" diff --git a/common/djangoapps/embargo/tests/test_middleware.py b/common/djangoapps/embargo/tests/test_middleware.py index eaf97b2eb3..5e1a908b8a 100644 --- a/common/djangoapps/embargo/tests/test_middleware.py +++ b/common/djangoapps/embargo/tests/test_middleware.py @@ -219,6 +219,7 @@ class EmbargoMiddlewareTests(ModuleStoreTestCase): self.assertEqual(response.status_code, 200) @ddt.data( + (None, False), ("", False), ("us", False), ("CU", True),