Code

Opened 5 years ago

Closed 5 years ago

#9714 closed (invalid)

Bug in manage.py --settings=mysettings

Reported by: fero Owned by: nobody
Component: Uncategorized Version: 1.0
Severity: Keywords: management
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Hello I use Django-1.0
and I hit the following bug:

I have a settings.py with my default settings
and a mysettings.py for developing purposes in which I simply override the DATABASE_USER variable

If I do:
# python manage.py dbshell --settings=mysettings

I get the error:

Traceback (most recent call last):
  File "manage.py", line 11, in <module>
    execute_manager(settings)
  File "/usr/local/sanet/django/core/management/__init__.py", line 340, in execute_manager
    utility.execute()
  File "/usr/local/sanet/django/core/management/__init__.py", line 295, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/local/sanet/django/core/management/base.py", line 77, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "/usr/local/sanet/django/core/management/base.py", line 96, in execute
    output = self.handle(*args, **options)
  File "/usr/local/sanet/django/core/management/base.py", line 178, in handle
    return self.handle_noargs(**options)
  File "/usr/local/sanet/django/core/management/commands/dbshell.py", line 10, in handle_noargs
    connection.client.runshell()
  File "/usr/local/sanet/django/db/backends/dummy/base.py", line 15, in complain
    raise ImproperlyConfigured, "You haven't set the DATABASE_ENGINE setting yet."
django.core.exceptions.ImproperlyConfigured: You haven't set the DATABASE_ENGINE setting yet.

I don't get the error if I do:

# DJANGO_SETTINGS_MODULE=mysettings python manage.py dbshell

Thank you for your work

Attachments (0)

Change History (3)

comment:1 Changed 5 years ago by ajs

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset

As far as I know if you supply an alternate settings file with --setting it completley replaces the standard settings.py

comment:2 Changed 5 years ago by fero

I investigate more and exporting the DJANGO_SETTINGS_MODULE variable does not raise an exception,
but does not work either (it is a fake :) )

mysettings.py file does not work if it is

import settings

DATABASE_USER = 'postgres' # Superuser role for the db backend of choice

however I noticed that I succeed in make it working if the file is

import settings

DATABASE_ENGINE = 'postgresql_psycopg2'
DATABASE_NAME = 'mydb'
DATABASE_USER = 'postgres' # Superuser role for the db backend of choice

It is a bit weird. Now I have no time to find the bug in django code.
It is a really strange behaviour.

comment:3 Changed 5 years ago by mtredinnick

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

There is no Django bug here. All settings variables must be in the module-level namespace of the settings file. In other words, Django looks for the all-capitals variables in the file you say is the settings file. So in your first case, there is not settings called DATABASE_USER. There is something in the settings namespace -- settings.DATABASE_USER, but you have told Django that the mysettings file contains all the settings, so it is look for mysettings.DATABASE_USER, in effect.

That is why every example that shows importing from one settings file into another uses from settings import *.

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.