#37361 closed Bug (fixed)
Permission renames do not apply to a chain of RenameModel operations
| Reported by: | Jacob Walls | Owned by: | Md. Saikat Islam |
|---|---|---|---|
| Component: | contrib.auth | Version: | 6.1 |
| Severity: | Release blocker | Keywords: | |
| Cc: | artirix1927 | Triage Stage: | Ready for checkin |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
#27489 implemented renaming permissions as part of RenameModel migration operations, but did not support a chain of multiple operations.
For a chain of renames A -> B -> C, the database is queried for permissions on A, and then for permissions on B, but because all planned renames are applied to the database in a second loop, the query for permissions on B in the first loop finds nothing, so no second permission rename is done in the second loop.
To reproduce:
- Define Class A
makemigrationsmigrate(this creates permissions)- Rename A -> B
makemigrations(answer "Y" to the rename prompt)- Rename B -> C
makemigrations(answer "Y" to the rename prompt)migrate -v2(this renames permissions)
Expected: permissions in database end with "C"
Actual:
Renamed permission(s): myapp.add_a → add_b Renamed permission(s): myapp.change_a → change_b Renamed permission(s): myapp.delete_a → delete_b Renamed permission(s): myapp.view_a → view_b Adding permission 'Permission object (49)' Adding permission 'Permission object (50)' Adding permission 'Permission object (51)' Adding permission 'Permission object (52)'
migrate myapp zero
RuntimeError: 4 permission rename conflict(s) detected.
Change History (8)
comment:1 by , 3 weeks ago
comment:2 by , 3 weeks ago
| Owner: | set to |
|---|---|
| Status: | new → assigned |
comment:3 by , 2 weeks ago
| Has patch: | set |
|---|---|
| Needs tests: | set |
| Triage Stage: | Unreviewed → Accepted |
comment:4 by , 2 weeks ago
Looking forward to get reviews: https://github.com/django/django/pull/22018
comment:5 by , 7 days ago
| Patch needs improvement: | set |
|---|
comment:6 by , 7 days ago
| Needs tests: | unset |
|---|---|
| Patch needs improvement: | unset |
| Triage Stage: | Accepted → Ready for checkin |
Pushed changes to account for the fact that codename is only unique together with content_type. Also tested backwards migrations more fully. The new version is good to go in my opinion.
I was able to reproduce it on Django
6.2.dev20260902172522. I’ll take this ticket once it’s marked as accepted. Looking forward to someone marking it as accepted.