[Django] #26756: Changing of model's verbose_name does not change the names of the model's permissions

9 views
Skip to first unread message

Django

unread,
Jun 14, 2016, 3:56:51 AM6/14/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
----------------------------+----------------------------------------------
Reporter: dburakov | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: 1.9
Severity: Normal | Keywords: permissions verbose_name migrate
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------+----------------------------------------------
I've found that changing the "verbose_name" of the Meta class of a model
and than running migrations does not change the names of the model's
permissions.

Steps to reproduce:

1. Create a new model

{{{
class AwesomeModel(models.Model):
class Meta:
verbose_name = "My awesome model"
}}}


2. Run "makemigrations" and than "migrate"
3. Look at the generated permissions


{{{
select * from auth_permission;
id | name | content_type_id |
codename
-----+----------------------------------------+-----------------+----------------------------------
1 | Can add my awesome model | 2 |
add_awesomemodel
2 | Can change my awesome model | 2 |
change_awesomemodel
3 | Can delete my awesome model | 2 |
delete_awesomemodel
}}}


4. Change the "verbose_name" of the Meta class of the model


{{{
class AwesomeModel(models.Model):
class Meta:
verbose_name = "My really awesome model"
}}}


5. Run "makemigrations" and than "migrate" again
6. Look at the generated permissions agaun

{{{

select * from auth_permission;
id | name | content_type_id |
codename
-----+----------------------------------------+-----------------+----------------------------------
1 | Can add my awesome model | 2 |
add_awesomemodel
2 | Can change my awesome model | 2 |
change_awesomemodel
3 | Can delete my awesome model | 2 |
delete_awesomemodel
}}}


As you can see the names of the model's permissions are not changed.
But! If now you drop the database and apply all the migrations to the
empty database - the permissions will have correct names


{{{
select * from auth_permission;
id | name | content_type_id |
codename
-----+----------------------------------------+-----------------+----------------------------------
1 | Can add my really awesome model | 2 |
add_awesomemodel
2 | Can change really my awesome model | 2 |
change_awesomemodel
3 | Can delete really my awesome model | 2 |
delete_awesomemodel
}}}

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

Django

unread,
Jun 14, 2016, 3:58:21 AM6/14/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------

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

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

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


Old description:

New description:

Steps to reproduce:

{{{

2 | Can change my really awesome model | 2 |
change_awesomemodel
3 | Can delete my really awesome model | 2 |
delete_awesomemodel
}}}

--

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

Django

unread,
Jun 14, 2016, 8:48:35 AM6/14/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------

Reporter: dburakov | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: permissions | Triage Stage: Accepted
verbose_name migrate |

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

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

* version: 1.9 => master
* stage: Unreviewed => Accepted


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

Django

unread,
Jun 14, 2016, 1:07:56 PM6/14/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------
Reporter: dburakov | Owner: black3r
Type: Bug | Status: assigned

Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: permissions | Triage Stage: Accepted
verbose_name migrate |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

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


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

Django

unread,
Jun 14, 2016, 1:29:50 PM6/14/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------
Reporter: dburakov | Owner: black3r
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: permissions | Triage Stage: Accepted
verbose_name migrate |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

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

* has_patch: 0 => 1


Comment:

I've tried to implement this in the management command, that handles
creating non-existing permissions after migrating an app.

Here's a PR https://github.com/django/django/pull/6778

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

Django

unread,
Jun 21, 2016, 3:28:16 PM6/21/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------
Reporter: dburakov | Owner: black3r
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: permissions | Triage Stage: Accepted
verbose_name migrate |
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:

I left a comment for improvement on the PR. Also tests are needed.

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

Django

unread,
Jun 26, 2016, 4:58:30 PM6/26/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------
Reporter: dburakov | Owner: black3r
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: permissions | Triage Stage: Accepted
verbose_name migrate |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by black3r):

I've tried the suggested injecting a migration operation approach, but
somehow ended up with an unexpected exception saying Permission model
cannot resolve 'content_type' into a field.

then i've tried optimizing my previous approach by only checking
permissions for models that had verbose_name altered during the migration.
that should be almost as effective as the suggested approach, and passed
the test I've written, so I created a new PR (
https://github.com/django/django/pull/6837 ) for that approach.

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

Django

unread,
Nov 15, 2016, 2:04:41 PM11/15/16
to django-...@googlegroups.com
#26756: Changing of model's verbose_name does not change the names of the model's
permissions
-------------------------------------+-------------------------------------
Reporter: Dmitry Burakov | Owner: Roman
| Hudec
Type: Bug | Status: assigned
Component: contrib.auth | Version: master

Severity: Normal | Resolution:
Keywords: permissions | Triage Stage: Accepted
verbose_name migrate |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Migrations => contrib.auth


Comment:

#27489 "Renaming a model doesn't rename the permission name and codename"
is a related issue that would be useful to work on while in this area.

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

Reply all
Reply to author
Forward
0 new messages