Content types and permissions are created for swapped models
|Reported by:||Thomas Schreiber||Owned by:||Russell Keith-Magee|
|Has patch:||yes||Needs documentation:||no|
|Needs tests:||yes||Patch needs improvement:||yes|
While trying to update django-guardian to support AUTH_USER_MODEL I discovered the contenttypes and permissions are still being created for auth.User
This means the auth.User app is still being loaded and I've traced the problem to this loop:
If someone could suggest where the correct place to put the check is, I'll be happy to put together a patch and test to reproduce the issue.
I think the following explicit check could work, but it could be better to keep the logic in model._meta for auth.User and check on that instead:
... for app in models.get_apps(): for model in models.get_models(app): if ('django.contrib.auth' in settings.INSTALLED_APPS and settings.AUTH_USER_MODEL != 'auth.User' and model.__name__ == 'User' and model.__module == 'django.contrib.auth.models'): continue if not model._meta.managed: continue if not router.allow_syncdb(self.connection.alias, model): continue tables.add(model._meta.db_table) tables.update([f.m2m_db_table() for f in model._meta.local_many_to_many]) ...
Change History (11)
comment:3 Changed 4 years ago by
|Summary:||auth.User should not be loaded when using a custom user model → Content types and permissions are created for swapped models|
|Triage Stage:||Unreviewed → Accepted|