Opened 6 years ago

Closed 6 years ago

Last modified 3 years ago

#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 Parth Patil, 6 years ago

Triage Stage: UnreviewedAccepted

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.

Last edited 6 years ago by Parth Patil (previous) (diff)

comment:2 by orlnub123, 6 years ago

Just non-upper ones. Some components such as diffsettings or the debug view rely on there only being uppercase settings.

I agree that someone might be using them but since it contradicts the documentation a deprecation period shouldn't be necessary.

Version 1, edited 6 years ago by orlnub123 (previous) (next) (diff)

comment:3 by Tim Graham, 6 years ago

Summary: Disallow non-upper settingsDisallow non-uppercase settings in settings.configure()

comment:4 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: newclosed

In 163236e:

Fixed #30234 -- Disallowed non-upper settings in settings.configure().

comment:5 by k4ml, 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.

in reply to:  5 ; comment:6 by Mariusz Felisiak, 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.

in reply to:  6 ; comment:7 by k4ml, 3 years ago

Replying to Mariusz Felisiak:

This ticket has nothing to do with using _ in settings.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.

Last edited 3 years ago by k4ml (previous) (diff)

in reply to:  7 comment:8 by Mariusz Felisiak, 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().

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