#29843: Create permissions using migration operations rather than using the
post_migrate signal
-------------------------------------+-------------------------------------
     Reporter:  Petter Strandmark    |                    Owner:  Arthur
         Type:                       |  Rio
  Cleanup/optimization               |                   Status:  assigned
    Component:  contrib.auth         |                  Version:  2.1
     Severity:  Normal               |               Resolution:
     Keywords:  contenttypes         |             Triage Stage:  Accepted
  permissions post_migrate           |
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
Changes (by Arthur Rio):

 * owner:  nobody => Arthur Rio
 * keywords:   => contenttypes permissions post_migrate
 * status:  new => assigned


Comment:

 I don't think we can solve the ticket for permissions unless we fix it for
 content types as well. The creation/deletion/renaming of permissions and
 content types should happen in the `makemigrations` phase as opposed to
 using a `post_migrate` signal.

 I suggest renaming this ticket to "Manage content types and permissions
 using migration operations rather than using the post_migrate signal",
 what do you think?

 The approach would be:
 - Add a `pre_makemigrations_write` signal, triggered right before the
 migrations are written to file
 - Content Type would register to that signal and insert operations if a
 model is created, deleted or renamed. If any operation is inserted, it
 would add itself to the dependencies of the migration
 - Add a `post_contenttypes_insert_migrations` signal, triggered if any
 content type operation is inserted
 - Permissions would register to that signal and insert operations if a
 model is created or deleted, or if any of the permissions of the model
 have changed (default or custom).  If any operation is inserted, it would
 add itself to the dependencies of the migration

 That way all the operations are part of the migration files and subsequent
 migration operations can use the new or updated permissions/content types.
 Also, it would handle having only `django.contrib.contenttypes` setup in
 the `INSTALLED_APPS` (i.e. not `django.contrib.auth`). I might be missing
 some edge cases, so any feedback would be appreciated.

 Finally, I'm not sure yet how to handle adding `django.contrib.auth` and
 `django.contrib.contenttypes` to the `INSTALLED_APPS` after migrations
 were already created for other models, but I think that we could keep the
 `post_migrate` signal in place to perform insert operations if
 `0001_initial` is part of the plan.

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

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.6468a01ce132da85d4ec937ba7d857c1%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to