From c3359135e773d41a2673ab7a694eb49057784ebe Mon Sep 17 00:00:00 2001 From: Renzo Lucioni Date: Thu, 4 Sep 2014 15:53:08 -0400 Subject: [PATCH] Refrain from accessing country code if country is None --- common/djangoapps/embargo/middleware.py | 2 +- common/djangoapps/embargo/tests/test_middleware.py | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) 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),