#31021 closed Bug (fixed)
0011_update_proxy_permissions crashes in multi database environment.
Reported by: | haudoing | Owned by: | Mariusz Felisiak |
---|---|---|---|
Component: | contrib.auth | Version: | 2.2 |
Severity: | Release blocker | Keywords: | |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
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.
Attachments (1)
Change History (20)
comment:1 by , 5 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
Summary: | migration doesn't work on multi database environment → migration doesn't work on multi database environment. |
comment:2 by , 5 years ago
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.
comment:3 by , 5 years ago
Resolution: | worksforme |
---|---|
Status: | closed → new |
comment:4 by , 5 years ago
Description: | modified (diff) |
---|
comment:5 by , 5 years ago
Description: | modified (diff) |
---|
comment:6 by , 5 years ago
Resolution: | → needsinfo |
---|---|
Status: | new → closed |
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 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 support channels.
comment:7 by , 5 years ago
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)```
comment:8 by , 5 years ago
I cannot reproduce this issue even with a proxy model :| . Can you attach a sample project?
by , 5 years ago
Attachment: | dj_2_2.zip added |
---|
comment:9 by , 5 years ago
Thank you Felixxm.
I've attach a zip file with a very simple Django project. That should reproduce this issue.
comment:10 by , 5 years ago
Sorry Felixxm,
The example is fine for brand new django 2.2.
It only appear when upgrade from 2.1 to 2.2
comment:11 by , 5 years ago
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.
comment:12 by , 5 years ago
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!
comment:13 by , 5 years ago
Resolution: | needsinfo |
---|---|
Severity: | Normal → Release blocker |
Status: | closed → new |
Summary: | migration doesn't work on multi database environment. → 0011_update_proxy_permissions crashes in multi database environment. |
Triage Stage: | Unreviewed → Accepted |
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,
comment:15 by , 5 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
This migration doesn't brake anything for me. I checked with an example from docs and it doesn't require a
default
DB.