#37361: Permission renames do not apply to a chain of RenameModel operations
-----------------------------+-------------------------------------------
Reporter: Jacob Walls | Type: Bug
Status: new | Component: contrib.auth
Version: 6.1 | Severity: Release blocker
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------+-------------------------------------------
#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:
1. Define Class A
2. `makemigrations`
3. `migrate` (this creates permissions)
4. Rename A -> B
5. `makemigrations` (answer "Y" to the rename prompt)
6. Rename B -> C
7. `makemigrations` (answer "Y" to the rename prompt)
8. `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)'
}}}
9. `migrate myapp zero`
{{{#!py
RuntimeError: 4 permission rename conflict(s) detected.
}}}
Bug in a040f555069971192220122555f187530d679d53.
--
Ticket URL: <
https://code.djangoproject.com/ticket/37361>
Django <
https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.