Opened 5 years ago

Closed 5 years ago

#15621 closed (fixed)

ImportError thrown in Fully Qualified Database Names are not re-raised

Reported by: keegan_csmith Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Keywords:
Cc: keegan_csmith Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:


If an ImportError occurs in a db supplied by django.db.backends it does not get re-raised. Instead the error is presented as a user configuration error. This only occurs if the backend is specified using a fully qualified name.

Attachments (1)

db-backend-error.diff (1.1 KB) - added by keegan_csmith 5 years ago.

Download all attachments as: .zip

Change History (5)

Changed 5 years ago by keegan_csmith

comment:1 Changed 5 years ago by adrian

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Resolution set to worksforme
  • Status changed from new to closed

I couldn't reproduce the bug. I changed my database engine to (and I don't have cx_Oracle installed on this machine), and it raised the correct ImportError --

>>> from django.db import connection
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.6/site-packages/django/db/", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "django/db/", line 91, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "django/db/", line 33, in load_backend
    return import_module('.base', backend_name)
  File "/Library/Python/2.6/site-packages/django/utils/", line 35, in import_module
  File "django/db/backends/oracle/", line 46, in <module>
    raise ImproperlyConfigured("Error loading cx_Oracle module: %s" % e)
django.core.exceptions.ImproperlyConfigured: Error loading cx_Oracle module: No module named cx_Oracle

Please reopen with more information on how to reproduce. Hope I'm not missing something obvious!

comment:2 Changed 5 years ago by keegan_csmith

  • Cc keegan_csmith added

It only happens if the module throws an ImportError. Here is throwing an ImproperlyConfigured Exception, so the correct behavior is occurring.

Unfortunately the only way to reproduce the behaviour is by modifying one of the db backends and importing a module which does not exist. The other way is by having a broken virtualenv, which is how I found the incorrect behaviour. I am not on the machine which has the broken virtualenv, so will post the backtrace I get later and reopen the ticket.

comment:3 Changed 5 years ago by keegan_csmith

  • Resolution worksforme deleted
  • Status changed from closed to reopened

So I don't know why this exception itself is happening, I think my sys.path is likely broken. But either way notice it says 'django.db.backends.sqlite3' isn't an available backend, when it is. This patch just corrects that error message.

keegan@mystery $ python example_project/ syncdb
Traceback (most recent call last):
  File "example_project/", line 12, in <module>
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/", line 438, in execute_manager
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/", line 379, in execute
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/", line 261, in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/", line 67, in load_command_class
    module = import_module('' % (app_name, name))
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/utils/", line 36, in import_module
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/management/commands/", line 10, in <module>
    import django.template.loaders.app_directories
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/template/loaders/", line 21, in <module>
    mod = import_module(app)
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/utils/", line 36, in import_module
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/contrib/admin/", line 1, in <module>
    from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/contrib/admin/", line 1, in <module>
    from django import forms
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/forms/", line 17, in <module>
    from models import *
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/forms/", line 6, in <module>
    from django.db import connections
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/db/", line 77, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/db/", line 92, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/db/", line 50, in load_backend
    raise ImproperlyConfigured(error_msg)
django.core.exceptions.ImproperlyConfigured: 'django.db.backends.sqlite3' isn't an available database backend. 
Try using django.db.backends.XXX, where XXX is one of:
    'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
Error was: cannot import name utils

comment:4 Changed 5 years ago by adrian

  • Resolution set to fixed
  • Status changed from reopened to closed

In [15871]:

(The changeset message doesn't reference this ticket)

Note: See TracTickets for help on using tickets.
Back to Top