From 8e9833f26199b99180877d043bf4e944b99af39b Mon Sep 17 00:00:00 2001 From: Adrian Holovaty Date: Fri, 26 May 2006 18:58:46 +0000 Subject: [PATCH] Fixed #1673 -- Every database backend now raises ImproperlyConfigured if the relevant Python database module raises ImportError git-svn-id: http://code.djangoproject.com/svn/django/trunk@2993 bcc190cf-cafb-0310-a4f2-bffc1f526a37 --- django/db/backends/ado_mssql/base.py | 6 +++++- django/db/backends/mysql/base.py | 6 +++++- django/db/backends/oracle/base.py | 6 +++++- django/db/backends/postgresql/base.py | 6 +++++- django/db/backends/postgresql_psycopg2/base.py | 6 +++++- django/db/backends/sqlite3/base.py | 6 +++++- 6 files changed, 30 insertions(+), 6 deletions(-) diff --git a/django/db/backends/ado_mssql/base.py b/django/db/backends/ado_mssql/base.py index fe36303565..c5a3b2cc33 100644 --- a/django/db/backends/ado_mssql/base.py +++ b/django/db/backends/ado_mssql/base.py @@ -5,7 +5,11 @@ Requires adodbapi 2.0.1: http://adodbapi.sourceforge.net/ """ from django.db.backends import util -import adodbapi as Database +try: + import adodbapi as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured, "Error loading adodbapi module: %s" % e import datetime try: import mx diff --git a/django/db/backends/mysql/base.py b/django/db/backends/mysql/base.py index e2d6cbfc5e..6a53956cad 100644 --- a/django/db/backends/mysql/base.py +++ b/django/db/backends/mysql/base.py @@ -5,7 +5,11 @@ Requires MySQLdb: http://sourceforge.net/projects/mysql-python """ from django.db.backends import util -import MySQLdb as Database +try: + import MySQLdb as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured, "Error loading MySQLdb module: %s" % e from MySQLdb.converters import conversions from MySQLdb.constants import FIELD_TYPE import types diff --git a/django/db/backends/oracle/base.py b/django/db/backends/oracle/base.py index 6a2c48e070..a7c866484e 100644 --- a/django/db/backends/oracle/base.py +++ b/django/db/backends/oracle/base.py @@ -5,7 +5,11 @@ Requires cx_Oracle: http://www.python.net/crew/atuining/cx_Oracle/ """ from django.db.backends import util -import cx_Oracle as Database +try: + import cx_Oracle as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured, "Error loading cx_Oracle module: %s" % e import types DatabaseError = Database.Error diff --git a/django/db/backends/postgresql/base.py b/django/db/backends/postgresql/base.py index 3c807f2120..a365434318 100644 --- a/django/db/backends/postgresql/base.py +++ b/django/db/backends/postgresql/base.py @@ -5,7 +5,11 @@ Requires psycopg 1: http://initd.org/projects/psycopg1 """ from django.db.backends import util -import psycopg as Database +try: + import psycopg as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured, "Error loading psycopg module: %s" % e DatabaseError = Database.DatabaseError diff --git a/django/db/backends/postgresql_psycopg2/base.py b/django/db/backends/postgresql_psycopg2/base.py index 9376c36772..13e7be7a98 100644 --- a/django/db/backends/postgresql_psycopg2/base.py +++ b/django/db/backends/postgresql_psycopg2/base.py @@ -5,7 +5,11 @@ Requires psycopg 2: http://initd.org/projects/psycopg2 """ from django.db.backends import util -import psycopg2 as Database +try: + import psycopg2 as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured, "Error loading psycopg2 module: %s" % e DatabaseError = Database.DatabaseError diff --git a/django/db/backends/sqlite3/base.py b/django/db/backends/sqlite3/base.py index b884e9d27b..7c3018aed9 100644 --- a/django/db/backends/sqlite3/base.py +++ b/django/db/backends/sqlite3/base.py @@ -3,7 +3,11 @@ SQLite3 backend for django. Requires pysqlite2 (http://pysqlite.org/). """ from django.db.backends import util -from pysqlite2 import dbapi2 as Database +try: + from pysqlite2 import dbapi2 as Database +except ImportError, e: + from django.core.exceptions import ImproperlyConfigured + raise ImproperlyConfigured, "Error loading pysqlite2 module: %s" % e DatabaseError = Database.DatabaseError