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.
* 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>
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>
* status: closed => new
* resolution: worksforme =>
--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:3>
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>
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 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
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>
* 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>
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>
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>
* Attachment "dj_2_2.zip" added.
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>
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>
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>
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>
* 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>
Comment (by felixxm):
Regression in 98296f86b340c8c9c968375d59f1d3a3479e60c2.
--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:14>
* status: new => assigned
* owner: nobody => felixxm
--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:15>
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/12153 PR]
--
Ticket URL: <https://code.djangoproject.com/ticket/31021#comment:16>
* 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>
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>
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>