Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#32642 closed Bug (invalid)

RuntimeError: 'apps.core.apps' declares more than one default AppConfig on custom admin setup

Reported by: Ron Owned by: nobody
Component: contrib.admin Version: 3.2
Severity: Normal Keywords:
Cc: Julien Chiron Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Hi!

I just migrated my project to django 3.2 and I get the following error:

RuntimeError: 'apps.core.apps' declares more than one default AppConfig: 'AdminConfig', 'CustomAdminConfig'.

Here is my apps.py:

from django.contrib.admin.apps import AdminConfig

class CustomAdminConfig(AdminConfig):
    default_site = 'apps.core.admin.site.CustomAdminSite'

To narrow down the bug I renamed the import:

from django.contrib.admin.apps import AdminConfig as XAdminConfig

class CustomAdminConfig(XAdminConfig):
    default_site = 'apps.core.admin.site.CustomAdminSite'

Then the error changes to:

RuntimeError: 'apps.core.apps' declares more than one default AppConfig: 'XAdminConfig', 'CustomAdminConfig'.

So I guess the new apps autoloader is following the import statement.

I looked at the docs (https://docs.djangoproject.com/en/3.2/ref/contrib/admin/#overriding-the-default-admin-site) but the described way seems like the stuff I did.

I honestly hope, I'm not making any stupid mistakes here.

Best regards and thx!
Ronny

Change History (4)

comment:1 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

As far as I'm aware it's not a bug in Django. First of all you should customize a default admin site inside a main project directory (like described in the documentation) not in an app, secondly INSTALLED_APPS must point to the config.

in reply to:  1 comment:2 by Julien Chiron, 3 years ago

Cc: Julien Chiron added
Resolution: invalid
Status: closednew

Having encountered the same kind of issue while implemeting site-wide custom AdminSite, I found a workaround to make it work.
It seems the documentation should be updated accordingly.

from django.contrib.admin.apps import AdminConfig

class MyAdminConfig(AdminConfig):
    default_site = 'myproject.admin.MyAdminSite'

This raises an exception:

RuntimeError: 'myproject.apps' declares more than one default AppConfig: 'AdminConfig', 'MyAdminConfig'.

It is solved by importing django.contrib.admin.apps instead of django.contrib.admin.apps.AdminConfig:

from django.contrib.admin import apps

class MyAdminConfig(apps.AdminConfig):
    default_site = 'myproject.admin.MyAdminSite'

Then the exception moves on:

django.core.exceptions.ImproperlyConfigured: Application labels aren't unique, duplicates: admin

This is caused by the settings.py configuration:

INSTALLED_APPS = [
    'myproject.apps.MyAdminConfig',  #replaces django.contrib.admin
   ...

It is solved by removing the 'MyAdminConfig' from the settings:

INSTALLED_APPS = [
    'myproject.apps', #replaces django.contrib.admin
   ...

comment:3 by Mariusz Felisiak, 3 years ago

Resolution: invalid
Status: newclosed

The current docs works for me.

comment:4 by Simon Meers, 3 years ago

I was able to reproduce this by using an apps.py module inside an app instead of the project -- I initially missed the myproject/apps.py in the docs and assumed it belonged in myapp/apps.py which generates the declares more than one default AppConfig RuntimeError.

Note: See TracTickets for help on using tickets.
Back to Top