#32692: Django 3.2 automatic AppConfig discovery breaks projects working in
3.1.8
-------------------------------+--------------------------------------
Reporter: Manel Clos | Owner: nobody
Type: Bug | Status: closed
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution: duplicate
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------
Changes (by Mariusz Felisiak):
* status: new => closed
* resolution: => duplicate
* component: Core (Other) => contrib.admin
Old description:
> The described method of overriding the default admin site
> (https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-the-
> default-admin-site), is not compatible with automatic AppConfig
> discovery, if the app (myproject, or myapps) is already in
> INSTALLED_APPS.
>
> **How to reproduce**
> - `pip install Django==3.2`
> - `django-admin startproject myproject`
> - `python manage.py migrate`
> - `python manage.py createsuperuser`
> - Put a template in `myproject/templates/admin/base_site.html`
> {{{
> {% extends 'admin/base_site.html' %}
>
> {% block branding %}
> Template test
> {% endblock %}
> }}}
> - Add `myproject` to `INSTALLED_APPS`
> {{{#!python
> INSTALLED_APPS = [
> 'myproject',
>
> 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> ]
> }}}
> - `python manage.py runserver` works, I can access the admin site and see
> the changes in templates
> - Follow the guide to override the default admin site,
> https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-the-
> default-admin-site, this is, create `myproject/admin.py`,
> `myproject/apps.py` and modify `settings.py`.
> {{{#!python
> # myproject/admin.py
> from django.contrib import admin
>
> class MyAdminSite(admin.AdminSite):
> index_title = 'Test'
>
> # myproject/apps.py
> from django.contrib.admin.apps import AdminConfig
>
> class MyAdminConfig(AdminConfig):
> default_site = 'myproject.admin.MyAdminSite'
>
> # myproject/settings.py
> INSTALLED_APPS = [
> 'myproject',
>
> 'myproject.apps.MyAdminConfig', # 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> ]
> }}}
> - `python manage.py runserver`
>
> **Actual result**
> `RuntimeError: 'myproject.apps' declares more than one default AppConfig:
> 'AdminConfig', 'MyAdminConfig'.``
>
> **This a regression**
> - `pip install Django==3.1.8`
> - `python manage.py runserver`
> - All ok, both templates and AdminConfig working at the same time
>
> **Workaroud**
> - use `app-admin.py` instead of `apps.py` when following the
> documentation to override the default admin site
> {{{#!python
> from django.contrib.admin.apps import AdminConfig
>
> class MyAdminConfig(AdminConfig):
> default_site = 'myproject.admin.MyAdminSite'
> }}}
> - adjust settings.py: `'myproject.apps-admin.MyAdminConfig'` in
> INSTALLED_APPS
> {{{#!python
> INSTALLED_APPS = [
> 'myproject',
>
> 'myproject.apps-admin.MyAdminConfig', # 'django.contrib.admin',
> 'django.contrib.auth',
> 'django.contrib.contenttypes',
> 'django.contrib.sessions',
> 'django.contrib.messages',
> 'django.contrib.staticfiles',
> ]
> }}}
> - works with Django 3.2 now!
New description:
The described method of overriding the default admin site
(https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-the-
default-admin-site), is not compatible with automatic AppConfig
discovery, if the app (myproject, or myapps) is already in INSTALLED_APPS.
**How to reproduce**
- `pip install Django==3.2`
- `django-admin startproject myproject`
- `python manage.py migrate`
- `python manage.py createsuperuser`
- Put a template in `myproject/templates/admin/base_site.html`
- Add `myproject` to `INSTALLED_APPS`
- `python manage.py runserver` works, I can access the admin site and see
the changes in templates
- Follow the guide to override the default admin site,
https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-the-
default-admin-site, this is, create `myproject/admin.py`,
`myproject/apps.py` and modify `settings.py`.
- `python manage.py runserver`
**Actual result**
`RuntimeError: 'myproject.apps' declares more than one default AppConfig:
'AdminConfig', 'MyAdminConfig'.``
**This a regression**
- `pip install Django==3.1.8`
- `python manage.py runserver`
- All ok, both templates and AdminConfig working at the same time
**Workaroud**
- use `app-admin.py` instead of `apps.py` when following the documentation
to override the default admin site
- adjust settings.py: `'myproject.apps-admin.MyAdminConfig'` in
INSTALLED_APPS
- works with Django 3.2
--
Comment:
IMO it's a duplicate of #30402. You should customize a default admin site
inside a main project directory (like described in the documentation) not
in an app.
Please feel-free to send a PR with docs adjustments if you think we should
make it clearer.
--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/067.f41d1964c9a774bf217b41ccc1b8aed5%40djangoproject.com.