[Django] #32692: Django 3.2 automatic AppConfig discovery breaks projects working in 3.1.8

393 views
Skip to first unread message

Django

unread,
Apr 28, 2021, 6:55:30 AM4/28/21
to django-...@googlegroups.com
#32692: Django 3.2 automatic AppConfig discovery breaks projects working in 3.1.8
----------------------------------------+------------------------
Reporter: Manel Clos | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.2
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
----------------------------------------+------------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/32692>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Apr 28, 2021, 7:31:29 AM4/28/21
to django-...@googlegroups.com
#32692: Django 3.2 automatic AppConfig discovery breaks projects working in 3.1.8
------------------------------+--------------------------------------

Reporter: Manel Clos | Owner: nobody
Type: Bug | Status: new
Component: Core (Other) | Version: 3.2
Severity: Normal | Resolution:

Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
------------------------------+--------------------------------------
Description changed by Manel Clos:

Old description:

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`

{{{
{% 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!

--

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:1>

Django

unread,
Apr 28, 2021, 7:35:51 AM4/28/21
to django-...@googlegroups.com
#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:

--

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

unread,
Apr 28, 2021, 7:44:52 AM4/28/21
to django-...@googlegroups.com
#32692: Django 3.2 automatic AppConfig discovery breaks projects working in 3.1.8
-------------------------------+--------------------------------------

Reporter: Manel Clos | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
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 Manel Clos):

* status: closed => new
* resolution: duplicate =>


Old description:

New description:

**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:

Hi, I reviewed #30402 and it is not the same bug. Also, the steps to
reproduce show that the admin site is customised inside the main project
as you suggest. Reopening.

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:3>

Django

unread,
Apr 28, 2021, 8:03:05 AM4/28/21
to django-...@googlegroups.com
#32692: Django 3.2 automatic AppConfig discovery breaks projects working in 3.1.8
-------------------------------+--------------------------------------

Reporter: Manel Clos | Owner: nobody
Type: Bug | Status: new
Component: contrib.admin | Version: 3.2
Severity: Normal | Resolution:
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Old description:

> - 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

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.

Example:


- `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'.``

Is 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
# myproject/apps_admin.py
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!

--

Comment (by Manel Clos):

Description updated with the example code that was overwritten in comment
2

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:4>

Django

unread,
Apr 28, 2021, 9:14:32 AM4/28/21
to django-...@googlegroups.com
#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: invalid

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: => invalid


Comment:

You shouldn't have `myproject` in the `INSTALLED_APPS` it's not an app.
Please use one of
[https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels
support channels] if you have further questions.

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:5>

Django

unread,
Apr 29, 2021, 9:44:41 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Manel Clos):

Ok, but take into account that this has worked on every Django version til
3.2, and there is no indication about what's wrong or deprecated, it just
stops working because of the automatic AppConfig discovery. Now I've to
create a different app just to put some *global* templates, sigh...

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:6>

Django

unread,
Apr 29, 2021, 9:55:46 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Manel Clos):

Hi Marius, just checked the documentation:
https://docs.djangoproject.com/en/3.2/ref/applications/#projects-and-
applications

The project package is often extended to include things like fixtures,
CSS, and templates which aren’t tied to a particular application.

There’s no restriction that a project package can’t also be considered
an application and have models, etc. (which would require adding it to
INSTALLED_APPS).

I really think Django 3.2 is breaking this, but I can open a different
ticket to fix the documentation if you prefer that.

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:7>

Django

unread,
Apr 29, 2021, 9:59:58 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

Replying to [comment:6 Manel Clos]:


> Ok, but take into account that this has worked on every Django version
til 3.2, and there is no indication about what's wrong or deprecated, it
just stops working because of the automatic AppConfig discovery. Now I've
to create a different app just to put some *global* templates, sigh...

Yes but it was only by chance, that kind of configuration wasn't
officially supported.

> Now I've to create a different app just to put some *global* templates,
sigh...

You don't need to have an app for global templates.

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:8>

Django

unread,
Apr 29, 2021, 10:04:28 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Carlton Gibson):

Specifically Manel you can use the `DIR` option to the `TEMPLATES` setting
to configure project level directories, rather than (mis)using `APP_DIRS`,
which loads the per-app templates, that you've been relying on up to now.

https://docs.djangoproject.com/en/3.2/ref/settings/#std:setting-TEMPLATES-
DIRS

See also the Overriding Templates How-To, which provides more of a walk
through of the configuration at the beginning.
https://docs.djangoproject.com/en/3.2/howto/overriding-templates/

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:9>

Django

unread,
Apr 29, 2021, 11:06:36 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Manel Clos):

Hi Carlton, I agree, but I'd also need to modify STATICFILES_DIRS, and
FIXTURES_DIRS, and maybe something else.

In the end it would be better to modify the AdminConfig documentation as
Marius suggested, even when this was previously working correctly up to
3.2.

Based on the tested workaround in the description, what about this?
https://github.com/manelclos/django/commit/c5da1ff59d6d53dc25cf503be9d59c1f825fb10a

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:10>

Django

unread,
Apr 29, 2021, 11:25:45 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Mariusz Felisiak):

> Based on the tested workaround in the description, what about this?
https://github.com/manelclos/django/commit/c5da1ff59d6d53dc25cf503be9d59c1f825fb10a

This change is not correct, you can still use `apps.py` unless you do this
in the main project and you don't use your project as an app, because it
will discover two configs. I think proposed change makes it even more
confusing.

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:11>

Django

unread,
Apr 29, 2021, 11:36:35 AM4/29/21
to django-...@googlegroups.com
#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: invalid
Keywords: | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------------------------

Comment (by Manel Clos):

Ok, would you consider a patch to
https://github.com/django/django/commit/e0519301238b43633bab64054772f9a62634a05f,
basically removing the last paragraph?

There's no restriction that a project package can't also be considered
an application and have models, etc. (which would require adding it to

:setting:`INSTALLED_APPS`).

Otherwise I'd consider this settled :)

--
Ticket URL: <https://code.djangoproject.com/ticket/32692#comment:12>

Reply all
Reply to author
Forward
0 new messages