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 10827 django.auth create_permissions must clear the content type cache before creating permissions Sean Legassick Tim Graham "I hit a problem which took some time to track down, where at the DB flush stage in a sequence of tests (using !TransactionTestCase) the recreation of permissions was failing with a FK constraint error. This was caused by inserting a permission referring to a content type that didn't exist in the DB. This happened because the content type was still in the cache, even thought the django_content_type table had been truncated. The cache hadn't been cleared because post_syncdb signal dispatch had called create_permissions before calling update_contenttypes (which does clear the cache and recreate the content types correctly). The real problem here is that create_permissions and update_contenttypes are both connected to the post_syncdb signal, with the former depending on the latter having been run first, but the dispatcher doesn't guarantee order of dispatch (or rather it dispatches in the order the signal handlers are connected, but that order depends on the order in which modules are loading which is not well-defined). Unfortunately that's a hard problem to solve, and I don't have any ideas about that short of substantive changes to the signal dispatcher. An easier solution to this particular problem is for create_permissions to clear the content types cache before it recreates permissions, that way the necesarry content types will be created as needed (see attached patch). " Bug closed contrib.auth dev Normal fixed jodym@… chris+django@… rjalves@… jorgecarleitao julenx@… Christoph Heer Jonas Trappenberg Accepted 1 0 0 0 0 0