diff --git a/common/djangoapps/embargo/middleware.py b/common/djangoapps/embargo/middleware.py index fe1727da1789..e7c199cc6e24 100644 --- a/common/djangoapps/embargo/middleware.py +++ b/common/djangoapps/embargo/middleware.py @@ -166,7 +166,7 @@ def _is_embargoed_by_profile_country(self, user, course_id="", course_is_embargo 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 eaf97b2eb3b9..5e1a908b8ac2 100644 --- a/common/djangoapps/embargo/tests/test_middleware.py +++ b/common/djangoapps/embargo/tests/test_middleware.py @@ -219,6 +219,7 @@ def test_ip_network_exceptions(self): self.assertEqual(response.status_code, 200) @ddt.data( + (None, False), ("", False), ("us", False), ("CU", True),