Opened 5 years ago

Closed 4 years ago

Last modified 4 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 5 years ago.

Download all attachments as: .zip

Change History (9)

Changed 5 years ago by Thomas Recouvreux

Attachment: out.txt added

comment:1 Changed 5 years ago by Thomas Recouvreux

Component: UncategorizedTesting framework
Keywords: test added
Type: UncategorizedBug

comment:2 Changed 5 years ago by Marten Kenbeek

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 Changed 5 years ago by Marten Kenbeek

Triage Stage: UnreviewedAccepted

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

comment:4 Changed 5 years ago by andrei kulakov

Owner: changed from nobody to andrei kulakov
Status: newassigned

comment:5 Changed 5 years ago by Tim Graham

Has patch: set
Patch needs improvement: set

I've reviewed the pull request.

comment:6 Changed 4 years ago by Tim Graham

Patch needs improvement: unset

comment:7 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In e2bfcab:

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

comment:8 Changed 4 years ago by Sjoerd Langkemper

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

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