Changes between Initial Version and Version 1 of Ticket #30351, comment 6


Ignore:
Timestamp:
Apr 15, 2019, 1:53:09 PM (5 years ago)
Author:
Arthur Rio

Legend:

Unmodified
Added
Removed
Modified
  • Ticket #30351, comment 6

    initial v1  
    1 We do not automatically delete stale content types on purpose to avoid data loss. When deleting a model, the `remove_stale_contenttypes.py` management command [https://github.com/django/django/blob/master/django/contrib/contenttypes/management/commands/remove_stale_contenttypes.py] should be ran. We can do two things here:
    2 1. Handle the `IntegrityError` with a helpful message to point to the command
    3 2. Re-use existing content types
     1What happens when creating a regular model, deleting it and creating a new proxy model:
    42
    5 I think 1. is safer but I am open to suggestions.
     31. Create model 'RegularThenProxyModel'
     4
     5{{{
     6+----------------------------------+---------------------------+-----------------------+
     7| name                             | codename                  | model                 |
     8+----------------------------------+---------------------------+-----------------------+
     9| Can add regular then proxy model | add_regularthenproxymodel | regularthenproxymodel |
     10+----------------------------------+---------------------------+-----------------------+
     11}}}
     12
     132. Migrate
     143. Delete the model called 'RegularThenProxyModel'
     154. Add a new proxy model called 'RegularThenProxyModel'
     16
     17{{{
     18+----------------------------------+---------------------------+-----------------------+
     19| name                             | codename                  | model                 |
     20+----------------------------------+---------------------------+-----------------------+
     21| Can add concrete model           | add_concretemodel         | concretemodel         |
     22| Can add regular then proxy model | add_regularthenproxymodel | concretemodel         |
     23| Can add regular then proxy model | add_regularthenproxymodel | regularthenproxymodel |
     24+----------------------------------+---------------------------+-----------------------+
     25}}}
     26
     27What happens when creating a proxy model right away:
     28
     291. Create a proxy model 'RegularThenProxyModel'
     30{{{
     31+----------------------------------+---------------------------+---------------+
     32| name                             | codename                  | model         |
     33+----------------------------------+---------------------------+---------------+
     34| Can add concrete model           | add_concretemodel         | concretemodel |
     35| Can add regular then proxy model | add_regularthenproxymodel | concretemodel |
     36+----------------------------------+---------------------------+---------------+
     37}}}
     38
     39As you can see, the problem here is that permissions are not cleaned up, so we are left with an existing `| Can add regular then proxy model | add_regularthenproxymodel | regularthenproxymodel |` row. When the 2.2 migration is applied, it tries to create that exact same row, hence the `IntegrityError`. Unfortunately, there is no `remove_stale_permission` management command like the one for `ContentType`. So I think we can do the following:
     40
     411. Show a nice error message to let the user delete the conflicting migration
     422. Re-use the existing permission
     43
     44I think 1. is much safer as it will force users to use a new permission and assign it accordingly to users/groups.
     45
     46**Edit**: ''I revised my initial comment after reproducing the error in my environment.''
Back to Top