#33013: "AppConfig" subclass imports found in Django 3.2's automatic "AppConfig"
discovery
-------------------------------+--------------------------------------
Reporter: Joseph Wayodi | Owner: nobody
Type: Bug | Status: closed
Component: Core (Other) | 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 Joseph Wayodi):
Oscar provides a drop-in replacement for Django's default `AppConfig`, for
use by Oscar itself, and by any projects that depend on it:
{{{
# oscar/core/application.py (Oscar's base "AppConfig" subclass)
class OscarConfig(AppConfig):
# Oscar's extensions to "AppConfig"
# oscar/apps/basket/apps.py (one of Oscar's apps)
from oscar.core.application import OscarConfig
class BasketConfig(OscarConfig):
# Oscar's "basket" app configurations
# project/settings.py (a project that depends on Oscar)
INSTALLED_APPS = [
...
'oscar.apps.basket',
...
]
}}}
With `default_app_config` for `oscar.apps.basket` set, the following
deprecation warning is displayed:
{{{
/project-venv/lib/python3.8/site-packages/django/apps/registry.py:91:
RemovedInDjango41Warning: 'oscar.apps.basket' defines default_app_config =
'oscar.apps.basket.apps.BasketConfig'. However, Django's automatic
detection did not find this configuration. You should move the default
config class to the apps submodule of your application and, if this module
defines several config classes, mark the default one with default = True.
app_config = AppConfig.create(entry)
}}}
If `default_app_config` for `oscar.apps.basket` is removed, Django finds
multiple non-default `AppConfig` subclasses (the imported `OscarConfig`,
and its subclass `BasketConfig`), and ends up using its default
`AppConfig` class.
If `OscarConfig.default` is set to `False`, this attribute gets inherited
by its `BasketConfig` subclass, and Django finds no default `AppConfig`
subclass, and ends up using its default `AppConfig` class. This would
require us to switch to specifying the app in `INSTALLED_APPS` using only
`oscar.apps.basket.apps.BasketConfig`. Or for projects using Oscar to
subclass `BasketConfig` just to set `BasketConfig.default` to `True`.
We could set `BasketConfig.default` to `True`, but this then causes a
problem for any project using Oscar, which should in turn be able to
subclass `BasketConfig`:
{{{
# project/basket/apps.py (overriden app in a project that depends on
Oscar)
from oscar.apps.basket.apps import BasketConfig
class OverriddenBasketConfig(BasketConfig):
# overridden "basket" app configurations
# project/settings.py (a project that depends on Oscar)
INSTALLED_APPS = [
...
'project.basket',
...
]
}}}
The `default` attribute gets inherited by its `OverriddenBasketConfig`
subclass, and Django finds multiple default `AppConfig` subclasses (the
imported `BasketConfig`, and its subclass `OverriddenBasketConfig`):
{{{
RuntimeError: 'project.basket.apps' declares more than one default
AppConfig: 'OverriddenBasketConfig', 'BasketConfig'.
}}}
Note that the same underlying issue exists with Django's own `AppConfig`,
which is why it is necessary to
[https://github.com/django/django/commit/3f2821af6bc48fa8e7970c1ce27bc54c3172545e
#diff-0f8bc657bc27c9f80385c4814c2c2ebc033bda3e03285a7212965309a481cc70R117
check for that special case]. What we are asking for is a generic solution
to that problem, which replacements for `AppConfig` can rely on.
--
Ticket URL: <https://code.djangoproject.com/ticket/33013#comment:4>
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/065.006b4c7dfb38461557d2fac5e94225da%40djangoproject.com.