Opened 2 months ago

Last modified 4 weeks ago

#29324 new Cleanup/optimization

Change Settings to raise ImproperlyConfigured on SECRET_KEY; not initialization

Reported by: Jon Dufresne Owned by: nobody
Component: Core (Other) Version: 2.1
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Since ticket #17800, initializing settings without a SECRET_KEY raises a an ImproperlyConfigured during settings initialization.

Instead, I think the error should be raised when the setting is accessed as Settings.SECRET_KEY.

My use case, my project has a number of management commands that run in a non-production, minimally configured environment. These management commands do not require SECRET_KEY, however, the environment is forced to provide one.

As a workaround this environment has been generating a random secret key each run. If Django were to instead raise the error on SECRET_KEY access, this workaround would not be necessary.

Change History (10)

comment:1 Changed 2 months ago by Jon Dufresne

Has patch: set

comment:2 Changed 2 months ago by Tim Graham

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

comment:3 Changed 2 months ago by Jon Dufresne

Patch needs improvement: unset

Updated PR to address feedback. Thanks.

comment:4 Changed 2 months ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In b3cffde5:

Fixed #29324 -- Made Settings raise ImproperlyConfigured if SECRET_KEY is accessed and not set.

comment:5 Changed 4 weeks ago by Marten Kenbeek

Resolution: fixed
Severity: NormalRelease blocker
Status: closednew

This causes a regression when using settings.configure(). UserSettingsHolder does not handle the missing SECRET_KEY attribute, and raises an AttributeError instead of ImproperlyConfigured.

(Discovered by bukensik in #django)

Last edited 4 weeks ago by Marten Kenbeek (previous) (diff)

comment:6 Changed 4 weeks ago by Tim Graham

Has patch: unset
Version: master2.1

comment:7 Changed 4 weeks ago by Tim Graham

Has patch: set

PR for the regression.

comment:8 Changed 4 weeks ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 5cc81cd9:

Reverted "Fixed #29324 -- Made Settings raise ImproperlyConfigured if SECRET_KEY is accessed and not set."

This reverts commit b3cffde5559c4fa97625512d7ec41a674be26076 due to
a regression and performance concerns.

comment:9 Changed 4 weeks ago by Tim Graham <timograham@…>

In 483f5d6c:

[2.1.x] Reverted "Fixed #29324 -- Made Settings raise ImproperlyConfigured if SECRET_KEY is accessed and not set."

This reverts commit b3cffde5559c4fa97625512d7ec41a674be26076 due to
a regression and performance concerns.

Backport of 5cc81cd9eb69f5f7a711412c02039b435c393135 from master

comment:10 Changed 4 weeks ago by Tim Graham

Has patch: unset
Resolution: fixed
Severity: Release blockerNormal
Status: closednew

I reverted the original patch for now as Claude expressed some concerns, "I'm not sure to like the additional test for every setting access, for a corner-case use case. I think we should consider reverting the initial patch instead."

I'll leave the ticket open for Jon to provide an alternative patch or to close the ticket as wontfix.

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