-
-
Notifications
You must be signed in to change notification settings - Fork 31.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #29324 -- Made Settings raise ImproperlyConfigured on SECRET_KEY access; not in init. #9876
Conversation
|
I see your point. I've updated the change to now do both:
Thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This message changed slightly:
diff --git a/tests/settings_tests/tests.py b/tests/settings_tests/tests.py
index 5a61895..09c062c 100644
--- a/tests/settings_tests/tests.py
+++ b/tests/settings_tests/tests.py
@@ -234,7 +234,8 @@ class SettingsTests(SimpleTestCase):
settings.TEST = 'test'
self.assertEqual('test', settings.TEST)
del settings.TEST
- with self.assertRaises(AttributeError):
+ msg = "'Settings' object has no attribute 'TEST'"
+ with self.assertRaisesMessage(AttributeError, msg):
getattr(settings, 'TEST')
def test_settings_delete_wrapped(self):
I don't know that it matters either way, but please test it.
django/conf/__init__.py
Outdated
@@ -115,15 +115,15 @@ def __init__(self, settings_module): | |||
if setting.isupper(): | |||
setting_value = getattr(mod, setting) | |||
|
|||
if setting == 'SECRET_KEY' and not setting_value: | |||
raise ImproperlyConfigured("The SECRET_KEY setting must not be empty.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use single quotes.
docs/ref/settings.txt
Outdated
@@ -2120,6 +2122,12 @@ affect them. | |||
startproject <startproject>` creates a unique ``SECRET_KEY`` for | |||
convenience. | |||
|
|||
.. versionchanged:: 2.1 | |||
|
|||
``SECRET_KEY`` is no longer defined by default. Django will now raise an |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is sufficient, "In older versions, SECRET_KEY defaults to an empty string." (use 4 space indent)
docs/ref/settings.txt
Outdated
@@ -2087,7 +2087,9 @@ Uses of the key shouldn't assume that it's text or bytes. Every use should go | |||
through :func:`~django.utils.encoding.force_text` or | |||
:func:`~django.utils.encoding.force_bytes` to convert it to the desired type. | |||
|
|||
Django will refuse to start if :setting:`SECRET_KEY` is not set. | |||
Django will refuse to start if :setting:`SECRET_KEY` is set to an empty value. | |||
An :class:`~django.core.exceptions.ImproperlyConfigured` exception will be |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is raised if SECRET_KEY is accessed but not set.
tests/admin_scripts/tests.py
Outdated
out, | ||
"+ INSTALLED_APPS = ['django.contrib.auth', 'django.contrib.contenttypes', 'admin_scripts']" | ||
) | ||
self.assertNotInOutput(out, "- SECRET_KEY = ''") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this assertion isn't needed.
Thanks for the review Tim. I've made the suggested changes. |
…Y is accessed and not set.
django/django#9876 removed the default SECRET_KEY, leading to an error when we try to access it in the tests
django/django#9876 removed the default SECRET_KEY, leading to an error when we try to access it in the tests closes #204
django/django#9876 removed the default SECRET_KEY, leading to an error when we try to access it in the tests closes #204
https://code.djangoproject.com/ticket/29324