Merge pull request #3088 from atleta/master

Handle AttributeError as well (when the imported module exists but the specified function/class does not).
This commit is contained in:
Tom Christie 2015-07-02 09:52:53 +01:00
commit 39ed03c21c

View File

@ -171,7 +171,7 @@ def import_from_string(val, setting_name):
module_path, class_name = '.'.join(parts[:-1]), parts[-1] module_path, class_name = '.'.join(parts[:-1]), parts[-1]
module = importlib.import_module(module_path) module = importlib.import_module(module_path)
return getattr(module, class_name) return getattr(module, class_name)
except ImportError as e: except (ImportError, AttributeError) as e:
msg = "Could not import '%s' for API setting '%s'. %s: %s." % (val, setting_name, e.__class__.__name__, e) msg = "Could not import '%s' for API setting '%s'. %s: %s." % (val, setting_name, e.__class__.__name__, e)
raise ImportError(msg) raise ImportError(msg)