[Django] #29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not initialization

29 views
Skip to first unread message

Django

unread,
Apr 13, 2018, 5:04:37 PM4/13/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
------------------------------------------------+------------------------
Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
------------------------------------------------+------------------------
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.

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

Django

unread,
Apr 13, 2018, 5:06:26 PM4/13/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
-------------------------------------+-------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: | Status: new
Cleanup/optimization |

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

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9876 PR]

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

Django

unread,
Apr 13, 2018, 9:14:54 PM4/13/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
Apr 14, 2018, 12:17:10 PM4/14/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* needs_better_patch: 1 => 0


Comment:

Updated PR to address feedback. Thanks.

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

Django

unread,
Apr 17, 2018, 2:09:46 PM4/17/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: closed

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

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"b3cffde5559c4fa97625512d7ec41a674be26076" b3cffde5]:
{{{
#!CommitTicketReference repository=""
revision="b3cffde5559c4fa97625512d7ec41a674be26076"
Fixed #29324 -- Made Settings raise ImproperlyConfigured if SECRET_KEY is
accessed and not set.
}}}

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

Django

unread,
May 21, 2018, 7:59:33 AM5/21/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: master
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* status: closed => new
* resolution: fixed =>
* severity: Normal => Release blocker


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:5>

Django

unread,
May 21, 2018, 12:58:59 PM5/21/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 2.1

Severity: Release blocker | 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 Tim Graham):

* has_patch: 1 => 0
* version: master => 2.1


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

Django

unread,
May 22, 2018, 4:18:10 PM5/22/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 2.1
Severity: Release blocker | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/9974 PR] for the regression.

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:7>

Django

unread,
May 26, 2018, 9:07:27 PM5/26/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Other) | Version: 2.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"5cc81cd9eb69f5f7a711412c02039b435c393135" 5cc81cd9]:
{{{
#!CommitTicketReference repository=""
revision="5cc81cd9eb69f5f7a711412c02039b435c393135"
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.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:8>

Django

unread,
May 26, 2018, 9:13:08 PM5/26/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: closed
Component: Core (Other) | Version: 2.1
Severity: Release blocker | Resolution: fixed
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

Comment (by Tim Graham <timograham@…>):

In [changeset:"483f5d6c4f66c8dfca5770de7b1af8aea05a5e7c" 483f5d6c]:
{{{
#!CommitTicketReference repository=""
revision="483f5d6c4f66c8dfca5770de7b1af8aea05a5e7c"
[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
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:9>

Django

unread,
May 26, 2018, 9:16:56 PM5/26/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 2.1
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 Tim Graham):

* status: closed => new


* has_patch: 1 => 0

* resolution: fixed =>
* severity: Release blocker => Normal


Comment:

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:10>

Django

unread,
Oct 14, 2018, 2:09:24 PM10/14/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

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

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/10512 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:11>

Django

unread,
Oct 20, 2018, 8:57:37 PM10/20/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Tim Graham):

* needs_better_patch: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:12>

Django

unread,
Nov 3, 2018, 7:35:44 AM11/3/18
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: closed

Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Jon Dufresne):

* status: new => closed
* resolution: => wontfix


Comment:

After researching the code necessary to handle the edge cases, I don't
think the complexity is worth it to include in Django. I'll stick with my
local project workaround instead.

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:13>

Django

unread,
Jul 26, 2020, 2:25:14 PM7/26/20
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
--------------------------------------+------------------------------------

Reporter: Jon Dufresne | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
--------------------------------------+------------------------------------
Changes (by Florian Apolloner):

* status: closed => new

* resolution: wontfix =>


Comment:

Reopening after recent ML discussion: https://groups.google.com/g/django-
developers/c/CIPgeTetYpk

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:14>

Django

unread,
Jul 27, 2020, 1:09:32 AM7/27/20
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: Florian
Type: | Apolloner
Cleanup/optimization | Status: assigned

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

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

* owner: nobody => Florian Apolloner


* needs_better_patch: 1 => 0

* status: new => assigned


Comment:

[https://github.com/django/django/pull/13240 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:15>

Django

unread,
Jul 28, 2020, 8:07:23 AM7/28/20
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: Florian
Type: | Apolloner
Cleanup/optimization | Status: assigned
Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

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

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:16>

Django

unread,
Jul 29, 2020, 3:07:11 AM7/29/20
to django-...@googlegroups.com
#29324: Change Settings to raise ImproperlyConfigured on SECRET_KEY; not
initialization
-------------------------------------+-------------------------------------
Reporter: Jon Dufresne | Owner: Florian
Type: | Apolloner
Cleanup/optimization | Status: closed

Component: Core (Other) | Version: 2.1
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by GitHub <noreply@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"948a874425e7d999950a8fa3b6598d9e34a4b861" 948a8744]:
{{{
#!CommitTicketReference repository=""
revision="948a874425e7d999950a8fa3b6598d9e34a4b861"
Fixed #29324 -- Made SECRET_KEY validation lazy (on first access).
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/29324#comment:17>

Reply all
Reply to author
Forward
0 new messages