Opened 5 years ago

Closed 3 years ago

#16743 closed Bug (worksforme) 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
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


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 (my production settings) and my python installation doesn't support postgresql. So, when i write:

$ python 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 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 5 years ago.
Late loading of db module in dumpdata command

Download all attachments as: .zip

Change History (4)

comment:1 Changed 5 years ago by Anssi Kääriäinen

Cc: anssi.kaariainen@… added
Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset
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.

Changed 5 years ago by Claude Paroz

Attachment: 16743-1.diff added

Late loading of db module in dumpdata command

comment:2 Changed 5 years ago by Claude Paroz

Has patch: set

Possible approach to this issue. Tests are not trivial.

comment:3 Changed 3 years ago by Claude Paroz

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