From bec651a427fc032d9115d30c8c5d0e702d754f6c Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Mon, 28 May 2018 16:18:53 +0200 Subject: Fixed #10827 -- Ensured ContentTypes are created before permission creation. --- tests/auth_tests/test_management.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'tests') diff --git a/tests/auth_tests/test_management.py b/tests/auth_tests/test_management.py index 4f29740982..73cf66699b 100644 --- a/tests/auth_tests/test_management.py +++ b/tests/auth_tests/test_management.py @@ -838,3 +838,15 @@ class CreatePermissionsTests(TestCase): state = migrations.state.ProjectState(real_apps=['contenttypes']) with self.assertNumQueries(0): create_permissions(self.app_config, verbosity=0, apps=state.apps) + + def test_create_permissions_checks_contenttypes_created(self): + """ + `post_migrate` handler ordering isn't guaranteed. Simulate a case + where create_permissions() is called before create_contenttypes(). + """ + # Warm the manager cache. + ContentType.objects.get_for_model(Group) + # Apply a deletion as if e.g. a database 'flush' had been executed. + ContentType.objects.filter(app_label='auth', model='group').delete() + # This fails with a foreign key constraint without the fix. + create_permissions(apps.get_app_config('auth'), interactive=False, verbosity=0) -- cgit v1.3