#30234 closed Bug (fixed)
Disallow non-uppercase settings in settings.configure()
Reported by: | orlnub123 | Owned by: | nobody |
---|---|---|---|
Component: | Core (Other) | Version: | dev |
Severity: | Normal | Keywords: | settings |
Cc: | Triage Stage: | Accepted | |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
Contradictory to the documentation, settings.configure()
and UserSettingsHolder.__getattr__()
allow non-upper settings to be set and retrieved, respectively. This allows for the following to happen:
import types from django.conf import settings settings.configure(types.SimpleNamespace(foo="bar"), baz="qux") print(settings.foo, settings.baz) # Doesn't error
Change History (8)
comment:1 by , 6 years ago
Triage Stage: | Unreviewed → Accepted |
---|
comment:2 by , 6 years ago
Just non-upper ones. Some components such as diffsettings or the debug view rely on there only being uppercase settings.
comment:3 by , 6 years ago
Summary: | Disallow non-upper settings → Disallow non-uppercase settings in settings.configure() |
---|
follow-up: 6 comment:5 by , 3 years ago
The docs still showing example that using _
in settings.py - https://github.com/django/django/blob/7f33c1e22dbc34a7afae7967783725b10f1f13b1/docs/ref/settings.txt#L1951
And this check cause issue when third party app is calling settings.configure():-
https://github.com/idlesign/pytest-djangoapp/blob/master/pytest_djangoapp/plugin.py#L42
If this is no longer recommended practice, the docs above should be fixed not to use _
anymore in settings.py.
follow-up: 7 comment:6 by , 3 years ago
Replying to k4ml:
The docs still showing example that using
_
in settings.py - https://github.com/django/django/blob/7f33c1e22dbc34a7afae7967783725b10f1f13b1/docs/ref/settings.txt#L1951
And this check cause issue when third party app is calling settings.configure():-
https://github.com/idlesign/pytest-djangoapp/blob/master/pytest_djangoapp/plugin.py#L42
If this is no longer recommended practice, the docs above should be fixed not to use
_
anymore in settings.py.
This ticket has nothing to do with using _
in settings.py
, it's about non-uppercase setting names.
follow-up: 8 comment:7 by , 3 years ago
Replying to Mariusz Felisiak:
This ticket has nothing to do with using
_
insettings.py
, it's about non-uppercase setting names.
_
failed isupper()
check.
Btw the fix is simple actually, add:-
del _
at the end of settings.py. The localization docs should add this in notes.
comment:8 by , 3 years ago
Replying to k4ml:
Btw the fix is simple actually, add:-
del _
at the end of settings.py. The localization docs should add this in notes.
It's not an issue in Django or its docs. It's an issue in pytest_djangoapp
. _
is not a setting name and should not be passed to the .configure()
.
I was able to reproduce this.
So are you suggesting to remove the support, to add and retrieve new settings?
I think this might be used as a feature by some people.