[Django] #24298: post-migrate handlers fail when DATABASES['default'] = {}

8 views
Skip to first unread message

Django

unread,
Feb 7, 2015, 7:10:57 AM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
----------------------------+----------------------------------
Reporter: trecouvr | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Keywords: migrate post_migrate
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------------------
On Django 1.7.4 the management command `migrate --database=xxx` fails when
`DATABASES['default'] = {}` with
`django.core.exceptions.ImproperlyConfigured: settings.DATABASES is
improperly configured. Please supply the ENGINE value. Check settings
documentation for more details.`.
On Django 1.7.3 it works fine.

To reproduct 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'),
}
}
}}}

3. Run `python manage.py migrate --database=mysite`

Problem:

It seems Django tries to access the default connection. I found
`django.db.migrations.loader.is_latest_migration_applied` uses the default
connection.


I am attaching an output log of the command.

--
Ticket URL: <https://code.djangoproject.com/ticket/24298>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 7, 2015, 7:13:20 AM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
-------------------------------------+-------------------------------------

Reporter: trecouvr | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Normal | Resolution:
Keywords: migrate | Triage Stage:
post_migrate | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by trecouvr):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Old description:

> On Django 1.7.4 the management command `migrate --database=xxx` fails
> when `DATABASES['default'] = {}` with
> `django.core.exceptions.ImproperlyConfigured: settings.DATABASES is
> improperly configured. Please supply the ENGINE value. Check settings
> documentation for more details.`.
> On Django 1.7.3 it works fine.
>
> To reproduct 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'),
> }
> }
> }}}
>
> 3. Run `python manage.py migrate --database=mysite`
>
> Problem:
>
> It seems Django tries to access the default connection. I found
> `django.db.migrations.loader.is_latest_migration_applied` uses the
> default connection.
>

> I am attaching an output log of the command.

New description:

On Django 1.7.4 the management command `migrate --database=xxx` fails when
`DATABASES['default'] = {}` with
`django.core.exceptions.ImproperlyConfigured: settings.DATABASES is
improperly configured. Please supply the ENGINE value. Check settings
documentation for more details.`.
On Django 1.7.3 it works fine.

To reproduct 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'),
}
}
}}}

3. Run `python manage.py migrate --database=mysite`

Problem:

It seems Django tries to access the default connection. I found
`django.db.migrations.loader.is_latest_migration_applied` uses the default
connection.


I am attaching an output log of the command.

Here is a sample project to reproduce the behaviour:
https://github.com/trecouvr/test_dj_migrate_174.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:1>

Django

unread,
Feb 7, 2015, 9:04:35 AM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------

Reporter: trecouvr | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution:
Keywords: migrate post_migrate | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by timgraham):

* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:2>

Django

unread,
Feb 7, 2015, 9:32:37 AM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: knbk
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by knbk):

* owner: nobody => knbk
* status: new => assigned
* easy: 0 => 1


Comment:

Seems easy enough, only 3 occurrences in the whole code-base.

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:3>

Django

unread,
Feb 7, 2015, 10:35:46 AM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: knbk
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by knbk):

Patch: https://github.com/knbk/django/compare/ticket_24298

I'm not too sure on the tests, I'd like some feedback on that before I
create a pull request.

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:4>

Django

unread,
Feb 7, 2015, 1:49:22 PM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: MarkusH
Type: Bug | Status: assigned
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution:
Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by MarkusH):

* owner: knbk => MarkusH


Comment:

I'm about to revert the patches for
[https://code.djangoproject.com/ticket/24075#comment:10 #24075].

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:5>

Django

unread,
Feb 7, 2015, 3:22:07 PM2/7/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: 1.7
Severity: Release blocker | Resolution: fixed

Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by MarkusH):

* status: assigned => closed
* resolution: => fixed


Comment:

Fixed in bd3d796ecd9a66832ad26024df65caeb63b60a5d and
2832a9b028c267997b2fd3dd0989670d57cdd08f.

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:6>

Django

unread,
Feb 8, 2015, 11:57:08 PM2/8/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution: fixed
Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by awol):

I think there is an additional failure scenario in the `Sites`
application. I haven't had the chance to track down the source of the
defect in `Sites`, in the event that I do, should I reopen this ticket or
submit a new ticket?

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:7>

Django

unread,
Feb 9, 2015, 4:37:45 AM2/9/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution: fixed
Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by trecouvr):

Thank you for the quick updates. Following the report of awol I updated my
test project and added a log file. I found the problem might come from the
`django.contrib.sites.management.create_default_site` function which calls
`Site.objects.exists` without propagating the `using` parameter. I dont
know either if I should create a new ticket or not.

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:8>

Django

unread,
Feb 9, 2015, 8:12:27 AM2/9/15
to django-...@googlegroups.com
#24298: post-migrate handlers fail when DATABASES['default'] = {}
--------------------------------------+------------------------------------
Reporter: trecouvr | Owner: MarkusH
Type: Bug | Status: closed
Component: Migrations | Version: 1.7

Severity: Release blocker | Resolution: fixed
Keywords: migrate post_migrate | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------+------------------------------------

Comment (by MarkusH):

Although it's a similar issue (missing use of `using`), it is still due to
another bug. It should be `Site.objects.using(using).exists()` in line 20.

Please open a separate issue for that.

--
Ticket URL: <https://code.djangoproject.com/ticket/24298#comment:9>

Reply all
Reply to author
Forward
0 new messages