From 2d0db67813d457dc890a2287d9e98593565d650f Mon Sep 17 00:00:00 2001 From: Joe Friedl Date: Sat, 30 Mar 2013 21:26:29 -0400 Subject: Fixed #20167 -- Preserve the traceback of `ImportError`s in `import_by_path`. Thanks @carljm for the review. --- django/utils/module_loading.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'django/utils/module_loading.py') diff --git a/django/utils/module_loading.py b/django/utils/module_loading.py index 01996743cd..ede585e562 100644 --- a/django/utils/module_loading.py +++ b/django/utils/module_loading.py @@ -3,6 +3,7 @@ import os import sys from django.core.exceptions import ImproperlyConfigured +from django.utils import six from django.utils.importlib import import_module @@ -19,8 +20,10 @@ def import_by_path(dotted_path, error_prefix=''): try: module = import_module(module_path) except ImportError as e: - raise ImproperlyConfigured('%sError importing module %s: "%s"' % ( - error_prefix, module_path, e)) + msg = '%sError importing module %s: "%s"' % ( + error_prefix, module_path, e) + six.reraise(ImproperlyConfigured, ImproperlyConfigured(msg), + sys.exc_info()[2]) try: attr = getattr(module, class_name) except AttributeError: -- cgit v1.3