Skip to content

Merging settings makes it almost impossible to fully override settings #2284

Description

@alexdutton

Describe the bug

In load_janeway_settings the settings referred to by DJANGO_SETTINGS_MODULE are merged into the base core.janeway_global_settings.

The method for merging involves appending to any existing sequence settings, and applying new keys to existing dictionaries. This means it's almost impossible to completely override sequence- or dict-based settings, and this behaviour is also potentially counter-intuitive.

For example, my attempt to insert a new middleware class into the existing Janeway default middleware list results in the default middleware being included twice:

from core import janeway_global_settings

MIDDLEWARE_CLASSES = list(janeway_global_settings.MIDDLEWARE_CLASSES)
MIDDLEWARE_CLASSES.insert(
    MIDDLEWARE_CLASSES.index("django.middleware.security.SecurityMiddleware") + 1,
    "whitenoise.middleware.WhiteNoiseMiddleware",
)

Janeway version

This is on master, currently 7739efb.

Expected behavior

One of three things:

  • A setting in DJANGO_SETTINGS_MODULE completely overrides the corresponding setting in global_janeway_settings, but the current custom configure_settings() behaviour continues, or
  • The current configure_settings() approach is removed, and from core.global_janeway_settings import * can be used in DJANGO_SETTINGS_MODULE to the same effect, making things more explicit, with no backwards-compatibility, or
  • load_janeway_settings could detect whether global_janeway_settings is *-imported into DJANGO_SETTINGS_MODULE — as the new preferred approach — and disable the settings-merging behavour. This would provide backwards-compatibility for the current behaviour.

Metadata

Metadata

Assignees

Labels

bugSomething's not working

Type

No type

Fields

No fields configured for issues without a type.

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions