From 06b06dbcedd0689f19e4b38c235bc1e520e8fea7 Mon Sep 17 00:00:00 2001 From: danxshap Date: Mon, 8 Sep 2014 18:28:49 -0400 Subject: [PATCH] Catch autodiscover module import error --- imagekit/utils.py | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/imagekit/utils.py b/imagekit/utils.py index 0973d35..31db1e8 100644 --- a/imagekit/utils.py +++ b/imagekit/utils.py @@ -76,16 +76,21 @@ def autodiscover(): _autodiscovered = True for app in settings.INSTALLED_APPS: - mod = import_module(app) - # Attempt to import the app's admin module. + # As of Django 1.7, settings.INSTALLED_APPS may contain classes instead of modules, hence the try/except + # See here: https://docs.djangoproject.com/en/dev/releases/1.7/#introspecting-applications try: - import_module('%s.imagegenerators' % app) - except: - # Decide whether to bubble up this error. If the app just - # doesn't have an imagegenerators module, we can ignore the error - # attempting to import it, otherwise we want it to bubble up. - if module_has_submodule(mod, 'imagegenerators'): - raise + mod = import_module(app) + # Attempt to import the app's admin module. + try: + import_module('%s.imagegenerators' % app) + except: + # Decide whether to bubble up this error. If the app just + # doesn't have an imagegenerators module, we can ignore the error + # attempting to import it, otherwise we want it to bubble up. + if module_has_submodule(mod, 'imagegenerators'): + raise + except ImportError: + pass def get_logger(logger_name='imagekit', add_null_handler=True):