Opened 8 years ago

Closed 8 years ago

Last modified 8 years ago

#25356 closed Bug (fixed)

startapp template mustn't encourage using default_app_config

Reported by: Aymeric Augustin Owned by: Aymeric Augustin
Component: Core (Management commands) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I just noticed that startapp now generates an apps.py. This isn't unreasonable. However it also sets default_app_config in __init__.py. I have strong doubts about this.

default_app_config is an ugly API that I included reluctantly for one targeted use-case: allowing pre-existing pluggable apps to take advantage of app config functionality in a backwards-compatible fashion, that is, without requiring projets to upgrade their INSTALLED_APPS settings. The first use of this feature was in django.contrib.admin in order to get rid of admin.autodiscover() in urls.py.

Relying implicitly on a default app config if one exists is clearly a bad practice. The good practice is to specifiy explicitly the full path to the AppConfig class in INSTALLED_APPS.

I recommend to:

  • remove this line from app_template/__init__.py
  • promote explicit configuration of app configs in INSTALLED_APPS
  • clarify the docs of default_app_config with the information I described above

Change History (12)

comment:1 Changed 8 years ago by Tim Graham

Owner: changed from nobody to Tim Graham
Status: newassigned
Triage Stage: UnreviewedAccepted

comment:2 Changed 8 years ago by Tim Graham

Has patch: set

comment:3 Changed 8 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: assignedclosed

In 862de0b:

Fixed #25356 -- Removed default_app_config from startapp template.

Also discouraged its use outside the intended use case.

comment:4 Changed 8 years ago by Aymeric Augustin

Has patch: unset
Resolution: fixed
Severity: Release blockerNormal
Status: closednew

Thanks Tim. Assigning to myself as a reminder to restructure the text a bit.

comment:5 Changed 8 years ago by Aymeric Augustin

Owner: changed from Tim Graham to Aymeric Augustin
Status: newassigned

comment:6 Changed 8 years ago by Aymeric Augustin

Has patch: set

comment:7 Changed 8 years ago by Tim Graham

Triage Stage: AcceptedReady for checkin

comment:8 Changed 8 years ago by Aymeric Augustin <aymeric.augustin@…>

In 94a36cfd:

Recommended against default_app_config.

Most likely this is a losing fight -- people seem to love this small
convention -- but at least the reasons for avoiding it will be
documented.

Refs #25356.

comment:9 Changed 8 years ago by Aymeric Augustin <aymeric.augustin@…>

In 76bf4bc:

[1.8.x] Recommended against default_app_config.

Most likely this is a losing fight -- people seem to love this small
convention -- but at least the reasons for avoiding it will be
documented.

Refs #25356.

Backport of 94a36cf from master

comment:10 Changed 8 years ago by Tim Graham

Resolution: fixed
Status: assignedclosed

comment:11 Changed 8 years ago by Tim Graham <timograham@…>

In 6258e163:

Refs #24971, #25356 -- Clarified how apps.py works in 1.9 release notes.

comment:12 Changed 8 years ago by Tim Graham <timograham@…>

In 7bbfc43e:

[1.9.x] Refs #24971, #25356 -- Clarified how apps.py works in 1.9 release notes.

Backport of 6258e163352690faf20bfc92c12468316d1a47ae from master

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