Opened 14 years ago

Closed 14 years ago

#15621 closed (fixed)

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

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

Description

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 Carruthers-Smith 14 years ago.

Download all attachments as: .zip

Change History (5)

by Keegan Carruthers-Smith, 14 years ago

Attachment: db-backend-error.diff added

comment:1 by Adrian Holovaty, 14 years ago

Resolution: worksforme
Status: newclosed

I couldn't reproduce the bug. I changed my database engine to django.db.backends.oracle (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/__init__.py", line 78, in <module>
    connection = connections[DEFAULT_DB_ALIAS]
  File "django/db/utils.py", line 91, in __getitem__
    backend = load_backend(db['ENGINE'])
  File "django/db/utils.py", line 33, in load_backend
    return import_module('.base', backend_name)
  File "/Library/Python/2.6/site-packages/django/utils/importlib.py", line 35, in import_module
    __import__(name)
  File "django/db/backends/oracle/base.py", 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 by Keegan Carruthers-Smith, 14 years ago

Cc: Keegan Carruthers-Smith added

It only happens if the module throws an ImportError. Here django.db.backends.oracle 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 by Keegan Carruthers-Smith, 14 years ago

Resolution: worksforme
Status: closedreopened

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.

(nexus)[~/repos/nexus]
keegan@mystery $ python example_project/manage.py syncdb
Traceback (most recent call last):
  File "example_project/manage.py", line 12, in <module>
    execute_manager(settings)
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/__init__.py", line 438, in execute_manager
    utility.execute()
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/__init__.py", line 379, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/core/management/__init__.py", 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/__init__.py", line 67, in load_command_class
    module = import_module('%s.management.commands.%s' % (app_name, name))
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/utils/importlib.py", line 36, in import_module
    __import__(name)
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/South-0.7.3-py2.6.egg/south/management/commands/__init__.py", 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/app_directories.py", 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/importlib.py", line 36, in import_module
    __import__(name)
  File "/home/keegan/.virtualenvs/nexus/lib/python2.6/site-packages/Django-1.2.3-py2.6.egg/django/contrib/admin/__init__.py", 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/helpers.py", 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/__init__.py", 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/models.py", 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/__init__.py", 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/utils.py", 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/utils.py", 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 by Adrian Holovaty, 14 years ago

Resolution: fixed
Status: reopenedclosed

In [15871]:

Fixed #15621 -- Fixed potentially confusing error message in db backend loading. Thanks, keegan_csmith

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