#35869: Add explicit warning when AppConfig.create() can't choose from multiple
subclasses of AppConfig
-------------------------------------+-------------------------------------
     Reporter:  narasux              |                     Type:
                                     |  Cleanup/optimization
       Status:  new                  |                Component:  Core
                                     |  (Other)
      Version:  5.0                  |                 Severity:  Normal
     Keywords:  AppConfig            |             Triage Stage:
                                     |  Unreviewed
    Has patch:  1                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------
 When I upgraded my Django project from 3.2 to 4.2, I found that the
 `ready` method in my custom AppConfig was never executed.

 Example Code:


 {{{
 # apps/demo/__init__.py

 default_app_config = "apps.demo.CustomAppConfig"
 }}}


 {{{
 # apps/demo/apps.py

 from django.apps import AppConfig


 class PlugableAppConfig(AppConfig):

     def ready(self):
         # do something...


 class CustomAppConfig(PlugableAppConfig):
     name = "apps.demo"

     def ready(self):
         super().ready()
         # do something...
 }}}

 After debugging, reading
 [https://docs.djangoproject.com/en/4.2/ref/applications/#configuring-
 applications documentation], and comparing version code, I determined that
 the reason was that Django 3.2 added support for
 
[https://github.com/django/django/commit/3f2821af6bc48fa8e7970c1ce27bc54c3172545e
 automatic detection for AppConfig] to replace `default_app_config`, and
 support for the latter was
 
[https://github.com/django/django/commit/75d6c4ae6df93c4c4d8621aced3a180afa18a6cb
 completely removed in version 4.1].

 This is a great new feature, but if there are **multiple subclasses** of
 AppConfig in apps.py and none of them specify  `default` as `True` (legacy
 code), `AppConfig.create()` will default to using the Base AppConfig
 
[https://github.com/django/django/blob/43287cbb87bc5e99a2fd384082a719d8b4d253c6/django/apps/config.py#L155
 without any explicit warning].

 This could lead to additional troubleshooting costs for developers.
 Therefore, I suggest that when `AppConfig.create()` cannot choose among
 multiple subclasses of AppConfig and defaults to using the Base AppConfig,
 a warning should be raised to alert developers.
-- 
Ticket URL: <https://code.djangoproject.com/ticket/35869>
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 visit 
https://groups.google.com/d/msgid/django-updates/01070192cd24c7e0-acc3c4ff-27fe-413b-a849-037a5f0334fd-000000%40eu-central-1.amazonses.com.

Reply via email to