Code

Opened 3 years ago

Closed 4 months 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 claudep 2 years ago.
Late loading of db module in dumpdata command

Download all attachments as: .zip

Change History (4)

comment:1 Changed 3 years ago by akaariai

  • Cc anssi.kaariainen@… added
  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Accepted

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 2 years ago by claudep

Late loading of db module in dumpdata command

comment:2 Changed 2 years ago by claudep

  • Has patch set

Possible approach to this issue. Tests are not trivial.

comment:3 Changed 4 months ago by claudep

  • Resolution set to worksforme
  • Status changed from new to closed

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

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.