#27645: Move Settings.__init__ checks to system checks
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: | Status: new
Cleanup/optimization |
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Someday/Maybe
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):
* owner: Clifford Gama => (none)
* stage: Accepted => Someday/Maybe
* status: assigned => new
Comment:
The presence of an `INSTALLED_APPS` check in `Settings.__init__()` make
this very difficult to solve:
When using management commands, `settings` are configured before system
checks are run because
[
https://github.com/django/django/blob/263f7319192b217c4e3b1eea0ea7809836392bbc/django/core/management/__init__.py#L381-L416
ManagementUtility.execute()] tries to configure the `settings` before
executing commands; `Command`s are then responsible for running the checks
they need to properly execute. This necessitates that the checks for this
ticket should somehow run independently of other checks, before them,
exiting if errors are found (otherwise other checks will crash because
`INSTALLED_APPS` invalid). An additional challenge here being properly
processing the errors as done in `BaseCommand.check().`
Supposing that were addressed, then additionally, accessing Django like
this:
{{{#!python
(djenv) clifford@anon:~/code/testing$ ipython
Python 3.12.3 (main, Sep 11 2024, 14:17:37) [GCC 13.2.0]
Type 'copyright', 'credits' or 'license' for more information
IPython 8.27.0 -- An enhanced Interactive Python. Type '?' for help.
In [1]: import os, django
In [2]: os.environ.setdefault("DJANGO_SETTINGS_MODULE",
"testing.settings")
Out[2]: 'testing.settings'
In [3]: from django.conf import settings
In [4]: settings.INSTALLED_APPS
Out[4]: "Not a list" # this bypasses system checks and will cause errors
later
}}}
would also need to be handled, no? I'm not sure if this is a use case.
All of this adds complexity that seems disproportionate to the benefits.
In light of these issues, I am resolving this as "maybe/someday."
--
Ticket URL: <
https://code.djangoproject.com/ticket/27645#comment:7>