﻿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
21923	Position of admin in INSTALLED_APPS in 1.7+ is now more important, and may raise warnings	Keryn Knight <django@…>	nobody	"Given the following example INSTALLED_APPS:

{{{
INSTALLED_APPS = (
    'django.contrib.contenttypes',
    'django.contrib.sites',
    'django.contrib.admin',
    'django.contrib.auth',
)
}}}

and using `python -W once ...`
will result in messages like: 
{{{
PendingDeprecationWarning: Model class django.contrib.auth.models.User doesn't declare an explicit app_label and either isn't in an application in INSTALLED_APPS or else was imported before its application was loaded. This will no longer be supported in Django 1.9.
}}}

with no indication of how to actually fix the problem going forward. Thanks to apollo13 pushing me to trace it down, the problem is that because admin depends on both sites and auth (and contenttypes), they need to appear before it in the INSTALLED_APPS. This has historically never been a problem (and wouldn't be until 1.9, based on this warning).

The imports that trigger it (for auth, anyway) is as follows:
'django.contrib.admin' -> the `__init__` does the import:
{{{ from django.contrib.admin.sites import AdminSite, site }}}
which in turn imports:
{{{ from django.contrib.admin.forms import AdminAuthenticationForm }}}
which in turn imports:
{{{ from django.contrib.auth.forms import AuthenticationForm }}}
which has a hard dependency on `User`:
{{{ from django.contrib.auth.models import User }}}
the only use of `User` in `auth.forms` appears to be in `UserCreationForm`'s `clean_username` method, which directly relies on `User` being in scope, rather than `get_user_model()` (which itself might not be filled yet, I don't know the internals well enough to say)

The warning is triggered when `django.setup()` is called, which calls `apps.populate()`, which eventually takes the string 'django.contrib.admin' and does `AppConfig.create(entry)` on it, which is where the `__import__` happens and the warnings are output.

For `contrib.sites`, the import chain is:
`__init__` does:
{{{ from django.contrib.admin.sites import AdminSite, site }}}
which imports:
{{{ from django.contrib.contenttypes import views as contenttype_views }}}
which imports:
{{{ from django.contrib.sites.models import Site }}} (and also {{{ from django.contrib.sites.shortcuts import get_current_site }}})

The issue may only be apparent if calling `settings.configure` and `django.setup` oneself, outside of the standard Django mechanisms, as this is how I've encountered it."	Cleanup/optimization	closed	contrib.admin	dev	Release blocker	fixed	app-loading		Ready for checkin	1	0	0	0	0	0
