[Django] #31021: migration doesn't work on multi database environment

91 views
Skip to first unread message

Django

unread,
Nov 21, 2019, 1:42:55 PM11/21/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment
----------------------------------------+------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
The tutorial said that we can omit to set the default database if default
doesn't makes sense
https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#defining-your-
databases

But the following script brake it
https://github.com/django/django/blob/stable/2.2.x/django/contrib/auth/migrations/0011_update_proxy_permissions.py

on line 42, it use

{{{
with transaction.atomic():
Permission.objects.filter(
permissions_query,
content_type=old_content_type,
).update(content_type=new_content_type)
}}}

This will brake the migration if default database doesn't set

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

Django

unread,
Nov 22, 2019, 7:10:29 AM11/22/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by felixxm):

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


Comment:

This migration doesn't brake anything for me. I checked with
[https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#an-example an
example] from docs and it doesn't require a `default` DB.

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

Django

unread,
Nov 26, 2019, 11:05:58 PM11/26/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: worksforme

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by haudoing):

Sorry for my poor English. I doesn't express it well. What I mean to say
is not migration script brake the multi db setting. I want to say after
configure multi database setting without default, the migration script
won't work. It throw the following exception while migrate

{{{
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/31021#comment:2>

Django

unread,
Nov 27, 2019, 12:08:23 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------

Reporter: haudoing | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by haudoing):

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


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

Django

unread,
Nov 27, 2019, 12:14:09 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------

Reporter: haudoing | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by haudoing:

Old description:

> The tutorial said that we can omit to set the default database if default
> doesn't makes sense
> https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#defining-your-
> databases
>
> But the following script brake it
> https://github.com/django/django/blob/stable/2.2.x/django/contrib/auth/migrations/0011_update_proxy_permissions.py
>
> on line 42, it use
>
> {{{
> with transaction.atomic():
> Permission.objects.filter(
> permissions_query,
> content_type=old_content_type,
> ).update(content_type=new_content_type)
> }}}
>
> This will brake the migration if default database doesn't set

New description:

The tutorial said that we can omit to set the default database if default
doesn't makes sense
https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#defining-your-
databases


But the following migration script doesn't work after configuration with
empty default database
https://github.com/django/django/blob/stable/2.2.x/django/contrib/auth/migrations/0011_update_proxy_permissions.py

on line 42, it use

{{{
with transaction.atomic():
Permission.objects.filter(
permissions_query,
content_type=old_content_type,
).update(content_type=new_content_type)
}}}

Tracebacks


{{{
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.
}}}

This will brake the migration if default database doesn't set

--

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

Django

unread,
Nov 27, 2019, 12:16:04 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------

Reporter: haudoing | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by haudoing:

Old description:

> The tutorial said that we can omit to set the default database if default

> But the following migration script doesn't work after configuration with
> empty default database


> https://github.com/django/django/blob/stable/2.2.x/django/contrib/auth/migrations/0011_update_proxy_permissions.py
>
> on line 42, it use
>
> {{{
> with transaction.atomic():
> Permission.objects.filter(
> permissions_query,
> content_type=old_content_type,
> ).update(content_type=new_content_type)
> }}}
>

> Tracebacks
> {{{
> 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.
> }}}
>

>


> This will brake the migration if default database doesn't set

New description:

The tutorial said that we can omit to set the default database if default
doesn't makes sense
https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#defining-your-
databases

But the following migration script doesn't work after configuration with
empty default database

https://github.com/django/django/blob/stable/2.2.x/django/contrib/auth/migrations/0011_update_proxy_permissions.py

on line 42, it use

{{{
with transaction.atomic():
Permission.objects.filter(
permissions_query,
content_type=old_content_type,
).update(content_type=new_content_type)
}}}
This will brake the migration if default database doesn't set

Tracebacks
{{{
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/31021#comment:5>

Django

unread,
Nov 27, 2019, 1:05:03 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by felixxm):

* status: new => closed

* resolution: => needsinfo


Comment:

> I want to say after configure multi database setting without default,
the migration script won't work. It throw the following exception while

migrate...

Just like I said, it works for me with
[https://docs.djangoproject.com/en/2.2/topics/db/multi-db/#an-example an
example] from docs, that doesn't require a `default` DB. Please don't
reopen this ticket without providing a small, sample project which we can
use to reproduce this issue. You can also try to one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels].

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

Django

unread,
Nov 27, 2019, 4:21:15 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by haudoing):

Hello Felixxm,

Thank you for your response. I found the actual reason cause this issue.
I do start a clean Django project with the example you provide, it really
works fine.
But when I create a proxy model then migration stop at that script again.
The script of the proxy model I made is as following

{{{
```class EditorUser(User):

class Meta:
proxy = True

def get_author_name(self):
'''
Returns:
a name leading by last_name
'''
return '{}{}'.format(self.last_name, self.first_name)```
}}}

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

Django

unread,
Nov 27, 2019, 4:35:15 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by felixxm):

I cannot reproduce this issue even with a proxy model :| . Can you attach
a sample project?

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

Django

unread,
Nov 27, 2019, 4:44:45 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Changes (by haudoing):

* Attachment "dj_2_2.zip" added.

Django

unread,
Nov 27, 2019, 4:46:42 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by haudoing):

Thank you Felixxm.

I've attach a zip file with a very simple Django project. That should
reproduce this issue.

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

Django

unread,
Nov 27, 2019, 5:25:26 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by haudoing):

Sorry Felixxm,

The example is fine for brand new django 2.2.
It only appear when upgrade from 2.1 to 2.2

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:10>

Django

unread,
Nov 27, 2019, 7:02:16 AM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by felixxm):

I've tried to reproduce this issue with your project by following these
steps:
- `pip install Django~=2.1.0`
- `python manage.py migrate --database=auth_db`
- `python manage.py migrate --database=others`
- `pip install Django~=2.2.0`
- `python manage.py migrate --database=auth_db`
- `python manage.py migrate --database=others`

and ... all works for me.

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:11>

Django

unread,
Nov 27, 2019, 9:35:24 PM11/27/19
to django-...@googlegroups.com
#31021: migration doesn't work on multi database environment.
------------------------------+--------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
Severity: Normal | Resolution: needsinfo

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------

Comment (by haudoing):

Please add a steps while working on Django 2.1 before migrate.

{{{
python manage.py makemigrations
}}}

That should reproduce this exception.
Though I'm not sure is it qualified to be a bug now.
After all A.B version upgrade doesn't 100% guarantee backward compatible.
But if it doesn't, it should be included in the release note, which it
doesn't.
https://docs.djangoproject.com/en/2.2/releases/2.2/#permissions-for-proxy-
models
Gotta thank you again felixxm!

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:12>

Django

unread,
Nov 28, 2019, 2:38:41 AM11/28/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------

Reporter: haudoing | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.2
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 felixxm):

* status: closed => new
* resolution: needsinfo =>
* severity: Normal => Release blocker
* stage: Unreviewed => Accepted


Comment:

Many thanks! I was able to reproduce this issue, fix is quite simple:
{{{
diff --git
a/django/contrib/auth/migrations/0011_update_proxy_permissions.py
b/django/contrib/auth/migrations/0011_update_proxy_permissions.py
index c3f617f438..62e0a91737 100644
--- a/django/contrib/auth/migrations/0011_update_proxy_permissions.py
+++ b/django/contrib/auth/migrations/0011_update_proxy_permissions.py
@@ -39,7 +39,7 @@ def update_proxy_model_permissions(apps, schema_editor,
reverse=False):
old_content_type = proxy_content_type if reverse else
concrete_content_type
new_content_type = concrete_content_type if reverse else
proxy_content_type
try:
- with transaction.atomic():
+ with
transaction.atomic(using=schema_editor.connection.alias):
Permission.objects.filter(
permissions_query,
content_type=old_content_type,
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:13>

Django

unread,
Nov 28, 2019, 2:45:24 AM11/28/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------
Reporter: haudoing | Owner: nobody
Type: Bug | Status: new
Component: contrib.auth | Version: 2.2
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 felixxm):

Regression in 98296f86b340c8c9c968375d59f1d3a3479e60c2.

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:14>

Django

unread,
Nov 28, 2019, 2:46:18 AM11/28/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------
Reporter: haudoing | Owner: felixxm
Type: Bug | Status: assigned
Component: contrib.auth | Version: 2.2

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 felixxm):

* status: new => assigned
* owner: nobody => felixxm


--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:15>

Django

unread,
Nov 28, 2019, 5:53:38 AM11/28/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------
Reporter: haudoing | Owner: felixxm
Type: Bug | Status: assigned
Component: contrib.auth | Version: 2.2

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 felixxm):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/12153 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:16>

Django

unread,
Nov 29, 2019, 5:11:49 AM11/29/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------
Reporter: haudoing | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2
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 Mariusz Felisiak <felisiak.mariusz@…>):

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


Comment:

In [changeset:"e8fcdaad5c428878d0a5d6ba820d957013f75595" e8fcdaad]:
{{{
#!CommitTicketReference repository=""
revision="e8fcdaad5c428878d0a5d6ba820d957013f75595"
Fixed #31021 -- Fixed proxy model permissions data migration crash with a
multiple databases setup.

Regression in 98296f86b340c8c9c968375d59f1d3a3479e60c2.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:17>

Django

unread,
Nov 29, 2019, 5:11:50 AM11/29/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------
Reporter: haudoing | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2

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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"ca9144a4a810dd509e468699c13325d8a1f5dcb1" ca9144a4]:
{{{
#!CommitTicketReference repository=""
revision="ca9144a4a810dd509e468699c13325d8a1f5dcb1"
[3.0.x] Fixed #31021 -- Fixed proxy model permissions data migration crash


with a multiple databases setup.

Regression in 98296f86b340c8c9c968375d59f1d3a3479e60c2.

Backport of e8fcdaad5c428878d0a5d6ba820d957013f75595 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:18>

Django

unread,
Nov 29, 2019, 5:12:29 AM11/29/19
to django-...@googlegroups.com
#31021: 0011_update_proxy_permissions crashes in multi database environment.
---------------------------------+------------------------------------
Reporter: haudoing | Owner: felixxm
Type: Bug | Status: closed
Component: contrib.auth | Version: 2.2

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 Mariusz Felisiak <felisiak.mariusz@…>):

In [changeset:"9a17ae50c61a3a0ea6c552ce4e3eab27f796d094" 9a17ae50]:
{{{
#!CommitTicketReference repository=""
revision="9a17ae50c61a3a0ea6c552ce4e3eab27f796d094"
[2.2.x] Fixed #31021 -- Fixed proxy model permissions data migration crash


with a multiple databases setup.

Regression in 98296f86b340c8c9c968375d59f1d3a3479e60c2.

Backport of e8fcdaad5c428878d0a5d6ba820d957013f75595 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:19>

Reply all
Reply to author
Forward
0 new messages