[Django] #27645: Move Settings.__init__ checks to system checks

36 views
Skip to first unread message

Django

unread,
Dec 26, 2016, 3:54:11 PM12/26/16
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
-------------------------------------+-------------------------------------
Reporter: Adam | Owner: Adam Chainz
Chainz |
Type: | Status: assigned
Cleanup/optimization |
Component: Core | Version: 1.10
(Other) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Following #27626 there is some settings validation code in
`Settings.__init__` which predates the system checks framework and would
be better moved to such checks.

--
Ticket URL: <https://code.djangoproject.com/ticket/27645>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 27, 2016, 6:04:55 AM12/27/16
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
-------------------------------------+-------------------------------------
Reporter: Adam Chainz | Owner: Adam
Type: | Chainz
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz):

* version: 1.10 => master
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/27645#comment:1>

Django

unread,
Dec 27, 2016, 1:28:41 PM12/27/16
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
-------------------------------------+-------------------------------------
Reporter: Adam Chainz | Owner: Adam
Type: | Chainz
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Tim Graham):

I noticed "Django will refuse to start if :setting:`SECRET_KEY` is not
set." in `docs/ref/settings.txt`." I'm unsure if the behavior should be
kept, but system checks aren't executed when running Django through
`wsgi.py` rather than through `runserver`.

--
Ticket URL: <https://code.djangoproject.com/ticket/27645#comment:2>

Django

unread,
Feb 6, 2021, 10:44:02 AM2/6/21
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: Cleanup/optimization | Status: new

Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Adam Johnson => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/27645#comment:3>

Django

unread,
Mar 18, 2024, 2:56:16 AM3/18/24
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Ülgen Sarıkavak):

* cc: Ülgen Sarıkavak (added)

--
Ticket URL: <https://code.djangoproject.com/ticket/27645#comment:4>

Django

unread,
Mar 18, 2024, 3:02:13 AM3/18/24
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
--------------------------------------+------------------------------------
Reporter: Adam Johnson | Owner: (none)
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Comment (by Adam Johnson):

948a874425e7d999950a8fa3b6598d9e34a4b861 moved the `SECRET_KEY` validation
so Tim’s comment no longer applies there.
--
Ticket URL: <https://code.djangoproject.com/ticket/27645#comment:5>

Django

unread,
Oct 9, 2024, 7:49:08 AM10/9/24
to django-...@googlegroups.com
#27645: Move Settings.__init__ checks to system checks
-------------------------------------+-------------------------------------
Reporter: Adam Johnson | Owner: Clifford
Type: | Gama
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: dev
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Clifford Gama):

* cc: Clifford Gama (added)
* owner: (none) => Clifford Gama
* status: new => assigned

--
Ticket URL: <https://code.djangoproject.com/ticket/27645#comment:6>

Django

unread,
Oct 11, 2024, 3:14:39 PM10/11/24
to django-...@googlegroups.com
#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>
Reply all
Reply to author
Forward
0 new messages