﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
29843	Create permissions using migration operations rather than using the post_migrate signal	Petter Strandmark	Arthur Rio	"We have encountered this problem when deploying our app to a new database.

The easiest way to demonstrate the problem is with this repository: https://github.com/PetterS/django-demo-app

First clone the repo and execute 
{{{
pipenv install
}}}

Then in a clean repository:
{{{
$ python manage.py migrate auth
$ python manage.py migrate myapp
}}}
This fails with ""django.contrib.auth.models.DoesNotExist: Permission matching query does not exist.""

Indeed, I can verify that the sqlite database does not contain any custom permissions. But showmigrations tells me that ""0001_initial"" and ""0002_auto_20181012_1052"" have been applied!
{{{
$ python manage.py showmigrations
...
myapp
 [X] 0001_initial
 [X] 0002_auto_20181012_1052
 [ ] 0003_auto_20181012_1054
}}}

On the other hand, in a clean repository the following succeeds:
{{{
$ python manage.py migrate auth
$ python manage.py migrate myapp 0001_initial
$ python manage.py migrate myapp 0002_auto_20181012_1052
$ python manage.py migrate myapp 0003_auto_20181012_1054
$ python manage.py migrate myapp
}}}
So the result of the migrations adding the permission is not visible until after the migrate command finished, even if there are other migrations coming after.


In a clean repository:
{{{
$ python manage.py migrate auth
$ python manage.py migrate myapp 0001_initial
}}}
""can_smell"" is now a permission in the DB.

I think this bug is pretty severe, since running migrate on a new DB will put the database in a state that is not very easy to recover from. The migrations show as applied, when in fact the permissions have not been created.

"	Cleanup/optimization	assigned	contrib.auth	dev	Normal		contenttypes permissions post_migrate	Petter Strandmark Arthur Rio Ryan Hiebert	Accepted	1	1	1	1	0	0
