Opened 13 years ago

Closed 11 years ago

#16743 closed Bug (worksforme)

django-admin.py check for database config includind during help subcommand

Reported by: jgomo3@… Owned by: nobody
Component: Core (Management commands) Version: 1.3
Severity: Normal Keywords: management django-admin.py manage.py
Cc: anssi.kaariainen@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

If database settings define a dabatase engine not supported by the Python installation, it fails trying to show the "help" of any database related subcommand (i.e. sql*, syncdb, dumpdata, etc.).

In my case, i have 'postgresql_psycopg2' as 'ENGINE' value of the default database in settings.py (my production settings) and my python installation doesn't support postgresql. So, when i write:

$ python manage.py help dumpdata

i receive

django.core.exceptions.ImproperlyConfigured: Error loading psycopg2 module: No module named psycopg2

It should simply show the help text. This problems also happen with the tab autocomplete, if the system autocomplete knows how to autocomplete the django-admin.py subcommands, as is in my case in an Ubuntu 11.04 installation and Django installed via apt-get.

Attachments (1)

16743-1.diff (2.0 KB ) - added by Claude Paroz 13 years ago.
Late loading of db module in dumpdata command

Download all attachments as: .zip

Change History (4)

comment:1 by Anssi Kääriäinen, 13 years ago

Cc: anssi.kaariainen@… added
Triage Stage: UnreviewedAccepted

I checked this, and the problem is that if you want to get the help text, you need to import the command class. The sql command classes use DEFAULT_DB_ALIAS from django.db and that is enough to get the ImproperlyConfigured Error. They uses the DEFAULT_DB_ALIAS as a default to --database option. And you don't have the help text available if you don't create the option. So, I don't see any trivial way to solve this. Allowing the import of DEFAULT_DB_ALIAS without an error and then being really careful about imports in commands would solve this, but that solution isn't ideal.

by Claude Paroz, 13 years ago

Attachment: 16743-1.diff added

Late loading of db module in dumpdata command

comment:2 by Claude Paroz, 13 years ago

Has patch: set

Possible approach to this issue. Tests are not trivial.

comment:3 by Claude Paroz, 11 years ago

Resolution: worksforme
Status: newclosed

Progress has been made on delaying some imports generally. With current master, I cannot reproduce this issue.

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