Opened 13 years ago
Closed 12 years ago
#17037 closed New feature (fixed)
Add management command to print active project settings
Reported by: | msabramo | Owned by: | Aymeric Augustin |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.3 |
Severity: | Normal | Keywords: | printsettings |
Cc: | msabramo | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
A large number of problems that we have with our Django project at work turn out to be because of settings that are not what they should be (note that our settings are not straightforward to see with a glance at settings.py since we use multiple settings files for production, dev, and common settings). I thought that it might be useful to have a Django management command that shows the settings in effect after all the settings files are processed.
It was super easy to write and is a tiny amount of code, but I have a feeling that this will quickly curtail a lot of problems.
Attachments (3)
Change History (23)
by , 13 years ago
Attachment: | django_manage_py_printsettings.diff added |
---|
comment:1 by , 13 years ago
Resolution: | → worksforme |
---|---|
Status: | new → closed |
It seems to me that this already exists: manage.py diffsettings.
Did I miss something in your proposal?
comment:2 by , 13 years ago
Cc: | added |
---|
comment:3 by , 13 years ago
Resolution: | worksforme |
---|---|
Status: | closed → reopened |
Sorry to reopen.
I didn't know about diffsettings. Thanks for pointing it out. Looks like it prints the settings that differ from Django core's default settings.
What my command does is slightly different. It prints out all the settings regardless of whether they are the same or different as the Django default.
So printsettings is simpler than diffsettings. I suppose both functions could be done by a single command (settings?) in order to minimize the # of commands, but I'll leave that question open. If folks want that, I can rework the patch.
comment:4 by , 13 years ago
Patch needs improvement: | set |
---|---|
Triage Stage: | Unreviewed → Accepted |
We could add an option to "diffsettings" to show the settings that are set to their default value too. They would be highlighted with a special marker, for instance ===
.
I don't expect this option to be widely used — Django has a huge number of settings and in most cases the default is OK — but it can't hurt.
I think we should keep the name "diffsettings". The backwards compatibility issues outweigh the semantic improvement of changing it to "settings".
by , 13 years ago
Attachment: | django_manage_py_diffsettings_all.diff added |
---|
Adds --all option to manage.py diffsettings
comment:5 by , 13 years ago
Patch needs improvement: | unset |
---|
See new patch django_manage_py_diffsettings_all.diff.
Some samples of use:
$ django diffsettings --all | grep '===' | head ABSOLUTE_URL_OVERRIDES = {} === ADMIN_FOR = () === ALLOWED_INCLUDE_ROOTS = () === APPEND_SLASH = True === AUTHENTICATION_BACKENDS = ('django.contrib.auth.backends.ModelBackend',) === CACHES = {'default': {'LOCATION': '', 'BACKEND': 'django.core.cache.backends.locmem.LocMemCache'}} === CACHE_MIDDLEWARE_ALIAS = 'default' === CACHE_MIDDLEWARE_KEY_PREFIX = '' === CACHE_MIDDLEWARE_SECONDS = 600 === COMMENTS_ALLOW_PROFANITIES = False ===
$ django diffsettings --help | grep --after=2 -- '--all' --all Display all settings; not just ones that differ from Django defaults. Settings that equal the defaults are followed by "===".
comment:6 by , 13 years ago
seems that this would be more suited as a contribution to django-extensions
comment:7 by , 13 years ago
Owner: | changed from | to
---|---|
Status: | reopened → new |
follow-up: 9 comment:8 by , 13 years ago
Owner: | changed from | to
---|
Please don't assign tickets to people without their consent.
comment:9 by , 13 years ago
Replying to aaugustin:
Please don't assign tickets to people without their consent.
Sorry. Was just trying to make sure you were in the loop on the patch that addressed your comment. I'll leave the assignments to you guys, though, since you know the protocol.
comment:10 by , 13 years ago
By convention, people assign to themselves tickets they intend to work on.
I triaged this ticket — it's better than leaving it unreviewed — but it isn't very high on my priority list, so I didn't assign it to myself.
follow-up: 13 comment:11 by , 13 years ago
Instead of using "===" to mark default settings, how about instead prefixing those lines with "# "? Then the output will be a valid settings file, with the settings not changed from the defaults commented out, which might be useful.
by , 13 years ago
Attachment: | django_manage_py_diffsettings_all_v2.diff added |
---|
Patch to add --all option to diffsettings management command
comment:13 by , 13 years ago
Replying to poirier:
Instead of using "===" to mark default settings, how about instead prefixing those lines with "# "? Then the output will be a valid settings file, with the settings not changed from the defaults commented out, which might be useful.
That's a great idea! OK, see attachment:django_manage_py_diffsettings_all_v2.diff
comment:14 by , 13 years ago
@poirier: Did you get a chance to look at the latest patch in attachment:django_manage_py_diffsettings_all_v2.diff
comment:15 by , 13 years ago
Note that since this stalled, I created a separate Django app for this:
comment:16 by , 12 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:17 by , 12 years ago
Needs tests: | set |
---|---|
Status: | assigned → new |
comment:18 by , 12 years ago
Needs tests: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
I added tests and docs.
Final patch: https://github.com/django/django/pull/914
ptone: if you're strongly against adding this to Django, just close this ticket as wontfix -- I don't care much one way or another.
comment:19 by , 12 years ago
I think this might be useful and does not add so much code, after all. +1
comment:20 by , 12 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Patch to add printsettings management command