[Django] #26930: makemigrations tries to access default databases even when set to empty

24 views
Skip to first unread message

Django

unread,
Jul 22, 2016, 11:32:51 AM7/22/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
----------------------------+--------------------
Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+--------------------
makemigrations always tries to access the default database, so it raises
an error when settings.DATABASES 'default' key is set to empty dict. This
was fixed previously in #22576, but there has been a regression.

The issue appears to be in
django/core/management/commands/makemigrations.py


{{{
for db in connections:
loader.check_consistent_history(connections[db])
}}}

in settings.py:

{{{
DATABASES = {
'default': {},
'leftside': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db-left.sqlite3'),
},
'rightside': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db-right.sqlite3'),
}
}

}}}

Then create a model in an application and define a router for it, and
then run {{{manage.py makemigrations}}}

With 1.8 and other releases this will create the migrations, but current
version raises an error:

{{{
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/core/management/__init__.py", line 367, in
execute_from_command_line
utility.execute()
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/core/management/__init__.py", line 359, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/core/management/base.py", line 305, in run_from_argv
self.execute(*args, **cmd_options)
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/core/management/base.py", line 356, in execute
output = self.handle(*args, **options)
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/core/management/commands/makemigrations.py", line 98, in
handle
loader.check_consistent_history(connections[db])
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/db/migrations/loader.py", line 276, in
check_consistent_history
applied = recorder.applied_migrations()
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/db/migrations/recorder.py", line 65, in applied_migrations
self.ensure_schema()
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/db/migrations/recorder.py", line 52, in ensure_schema
if self.Migration._meta.db_table in
self.connection.introspection.table_names(self.connection.cursor()):
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/db/backends/base/base.py", line 238, in cursor
cursor = self.make_debug_cursor(self._cursor())
File "/home/lemon/code/envs/dj34/lib/python3.4/site-
packages/django/db/backends/dummy/base.py", line 21, in complain
raise ImproperlyConfigured("settings.DATABASES is improperly
configured. "
django.core.exceptions.ImproperlyConfigured: settings.DATABASES is
improperly configured. Please supply the ENGINE value. Check settings
documentation for more details.
}}}

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

Django

unread,
Jul 22, 2016, 1:30:59 PM7/22/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | 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
* needs_better_patch: => 0
* needs_tests: => 0
* version: master => 1.10
* needs_docs: => 0
* stage: Unreviewed => Accepted


Comment:

Regression in 1.10 due to 02ae5fd31a56ffb42feadb49c1f3870ba0a24869.

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

Django

unread,
Jul 23, 2016, 5:48:18 AM7/23/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by claudep):

That's what happen when fixes are committed without tests :-/

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

Django

unread,
Jul 23, 2016, 6:06:29 AM7/23/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* Attachment "26930-test.diff" added.

Failing test case

Django

unread,
Jul 23, 2016, 8:16:45 AM7/23/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* Attachment "26930-patch.diff" added.

fixes the issue

Django

unread,
Jul 23, 2016, 8:18:56 AM7/23/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1


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

Django

unread,
Jul 23, 2016, 9:34:17 AM7/23/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by lizlemon):

pull request
https://github.com/django/django/pull/6967

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

Django

unread,
Jul 25, 2016, 6:56:29 AM7/25/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

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

* needs_better_patch: 0 => 1


Comment:

As noted on the PR, I don't using `is_usable()` is the best way to
identify the dummy database backend.

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

Django

unread,
Jul 30, 2016, 9:16:58 PM7/30/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------

Reporter: lizlemon | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* needs_better_patch: 1 => 0


Comment:

New [https://github.com/django/django/pull/6994 PR]

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

Django

unread,
Aug 1, 2016, 7:57:32 AM8/1/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------
Reporter: lizlemon | Owner: nobody
Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution: fixed

Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------
Changes (by GitHub <noreply@…>):

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


Comment:

In [changeset:"aad46c3e370e105f9117a337924090d05f1b001d" aad46c3]:
{{{
#!CommitTicketReference repository=""
revision="aad46c3e370e105f9117a337924090d05f1b001d"
Fixed #26930 -- Prevented makemigrations from accessing an empty database.

Thanks Liz Lemon for the report and investigation and
Claude Paroz for the test.
}}}

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

Django

unread,
Aug 1, 2016, 8:03:16 AM8/1/16
to django-...@googlegroups.com
#26930: makemigrations tries to access default databases even when set to empty
---------------------------------+------------------------------------
Reporter: lizlemon | Owner: nobody

Type: Bug | Status: closed
Component: Migrations | Version: 1.10
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
---------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"ddcf7dbae7f6e5fd3c3398aba13bf55b95c80a62" ddcf7dba]:
{{{
#!CommitTicketReference repository=""
revision="ddcf7dbae7f6e5fd3c3398aba13bf55b95c80a62"
[1.10.x] Fixed #26930 -- Prevented makemigrations from accessing an empty
database.

Thanks Liz Lemon for the report and investigation and
Claude Paroz for the test.

Backport of aad46c3e370e105f9117a337924090d05f1b001d from master
}}}

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

Reply all
Reply to author
Forward
0 new messages