summaryrefslogtreecommitdiff
path: root/django/db/utils.py
diff options
context:
space:
mode:
authorTim Graham <timograham@gmail.com>2017-01-24 08:33:26 -0500
committerGitHub <noreply@github.com>2017-01-24 08:33:26 -0500
commita87d6b69a75d0f9a66652e3f0bd1c2c85624c7d5 (patch)
tree3e722414876e97365244a9986fc64bb80a746370 /django/db/utils.py
parent435e4bf38e97255acd97eacadeb8fe312ba97aff (diff)
Tidied djang.db.utils.load_backend().
Removed an unneeded EnvironmentError catching and used "raise from exc" syntax.
Diffstat (limited to 'django/db/utils.py')
-rw-r--r--django/db/utils.py26
1 files changed, 11 insertions, 15 deletions
diff --git a/django/db/utils.py b/django/db/utils.py
index dfdeff9c51..1bf44cbe26 100644
--- a/django/db/utils.py
+++ b/django/db/utils.py
@@ -111,23 +111,19 @@ def load_backend(backend_name):
return import_module('%s.base' % backend_name)
except ImportError as e_user:
# The database backend wasn't found. Display a helpful error message
- # listing all possible (built-in) database backends.
+ # listing all built-in database backends.
backend_dir = os.path.join(os.path.dirname(__file__), 'backends')
- try:
- builtin_backends = [
- name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
- if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'}
- ]
- except EnvironmentError:
- builtin_backends = []
- if backend_name not in ['django.db.backends.%s' % b for b in
- builtin_backends]:
+ builtin_backends = [
+ name for _, name, ispkg in pkgutil.iter_modules([backend_dir])
+ if ispkg and name not in {'base', 'dummy', 'postgresql_psycopg2'}
+ ]
+ if backend_name not in ['django.db.backends.%s' % b for b in builtin_backends]:
backend_reprs = map(repr, sorted(builtin_backends))
- error_msg = ("%r isn't an available database backend.\n"
- "Try using 'django.db.backends.XXX', where XXX "
- "is one of:\n %s\nError was: %s" %
- (backend_name, ", ".join(backend_reprs), e_user))
- raise ImproperlyConfigured(error_msg)
+ raise ImproperlyConfigured(
+ "%r isn't an available database backend.\n"
+ "Try using 'django.db.backends.XXX', where XXX is one of:\n"
+ " %s" % (backend_name, ", ".join(backend_reprs))
+ ) from e_user
else:
# If there's some other error, this must be an error in Django
raise