From 4a3f2b4418a8ca77c482f03460457131683758fa Mon Sep 17 00:00:00 2001 From: David Moreau Simard Date: Mon, 21 Jan 2019 11:48:28 -0500 Subject: [PATCH] Use import instead of sys.modules for verifying ara-server availability If ara.server hasn't been imported already, it won't be there. Change-Id: I6d9c79142b33882cf634db1c439c1df6f2c96c5c --- ara/clients/offline.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/ara/clients/offline.py b/ara/clients/offline.py index 9edd1d0..072f06b 100644 --- a/ara/clients/offline.py +++ b/ara/clients/offline.py @@ -33,8 +33,11 @@ class AraOfflineClient(AraHttpClient): def __init__(self): self.log = logging.getLogger(__name__) - # Validate that ara-server is installed - if "ara.server" not in sys.modules: + # Validate that ara-server is available before letting Django attempt to + # import it + try: + import ara.server + except ImportError: raise ImportError("AraOfflineClient requires ara-server to be installed.") from django import setup as django_setup