Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#24394 closed Bug (fixed)

Running tests fails when DATABASES['default'] = {}

Reported by: Thomas Recouvreux Owned by: andrei kulakov
Component: Testing framework Version: 1.7
Severity: Normal Keywords: test
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

On Django 1.7.x the management command test fails when DATABASES['default'] = {} with AttributeError: 'DatabaseWrapper' object has no attribute 'Database'.
This failure is also present on 1.7.3 and 1.7.4 version of Django.

To reproduce the problem:

  1. Create a new project
  2. Edit the settings.py this way:
DATABASES = {
    'default': {},
    'mysite': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, 'db_mysite.sqlite3'),
    }
}
  1. Add a dummy test to yout project, for example:
from django.test import TestCase


class MyTestCase(TestCase):
    def test_pouet(self):
        pass
  1. Run python manage.py test

Problem:

It seems Django instantiate a dummy connector for default and then calls not implemented methods on this connector.

I am attaching the output log of the command.
Here is a sample project to reproduce the behaviour: ​​https://github.com/trecouvr/test_dj_migrate_174.

Attachments (1)

out.txt (2.3 KB ) - added by Thomas Recouvreux 10 years ago.

Download all attachments as: .zip

Change History (9)

by Thomas Recouvreux, 10 years ago

Attachment: out.txt added

comment:1 by Thomas Recouvreux, 10 years ago

Component: UncategorizedTesting framework
Keywords: test added
Type: UncategorizedBug

comment:2 by Marten Kenbeek, 10 years ago

I've opened a discussion on this on the mailing list: https://groups.google.com/forum/#!topic/django-developers/VWyP5M7cRyk

I feel this is more a design decision than a bug. The documentation states that default is required but not in which way. A strict interpretation would conclude that DATABASES['default'] = {} is sufficient, but I personally have always interpreted this as "default requires a valid database configuration".

comment:3 by Marten Kenbeek, 10 years ago

Triage Stage: UnreviewedAccepted

It is indeed a bug, as the documentation on multi-db setups explicitly allows this.

comment:4 by andrei kulakov, 10 years ago

Owner: changed from nobody to andrei kulakov
Status: newassigned

comment:5 by Tim Graham, 10 years ago

Has patch: set
Patch needs improvement: set

I've reviewed the pull request.

comment:6 by Tim Graham, 10 years ago

Patch needs improvement: unset

comment:7 by Tim Graham <timograham@…>, 10 years ago

Resolution: fixed
Status: assignedclosed

In e2bfcab:

Fixed #24394 -- Allowed running tests with empty default dictionary.

comment:8 by Sjoerd Langkemper, 9 years ago

I filed a bug for similar behavior in Django 1.9a1: #25504

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