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)

django_manage_py_printsettings.diff (676 bytes ) - added by msabramo 13 years ago.
Patch to add printsettings management command
django_manage_py_diffsettings_all.diff (1.3 KB ) - added by msabramo 13 years ago.
Adds --all option to manage.py diffsettings
django_manage_py_diffsettings_all_v2.diff (1.3 KB ) - added by msabramo 13 years ago.
Patch to add --all option to diffsettings management command

Download all attachments as: .zip

Change History (23)

by msabramo, 13 years ago

Patch to add printsettings management command

comment:1 by Aymeric Augustin, 13 years ago

Resolution: worksforme
Status: newclosed

It seems to me that this already exists: manage.py diffsettings.

Did I miss something in your proposal?

comment:2 by msabramo, 13 years ago

Cc: msabramo added

comment:3 by msabramo, 13 years ago

Resolution: worksforme
Status: closedreopened

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 Aymeric Augustin, 13 years ago

Patch needs improvement: set
Triage Stage: UnreviewedAccepted

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 msabramo, 13 years ago

Adds --all option to manage.py diffsettings

comment:5 by msabramo, 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 Preston Holmes, 13 years ago

seems that this would be more suited as a contribution to django-extensions

comment:7 by msabramo, 13 years ago

Owner: changed from nobody to Aymeric Augustin
Status: reopenednew

comment:8 by Aymeric Augustin, 13 years ago

Owner: changed from Aymeric Augustin to nobody

Please don't assign tickets to people without their consent.

in reply to:  8 comment:9 by anonymous, 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 Aymeric Augustin, 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.

comment:11 by Dan Poirier, 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.

comment:12 by msabramo, 13 years ago

Owner: changed from nobody to msabramo

Assigning to myself so I can work on this.

by msabramo, 13 years ago

Patch to add --all option to diffsettings management command

in reply to:  11 comment:13 by msabramo, 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 anonymous, 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 msabramo, 13 years ago

Note that since this stalled, I created a separate Django app for this:

http://pypi.python.org/pypi/django-print-settings/

comment:16 by Aymeric Augustin, 12 years ago

Owner: changed from msabramo to Aymeric Augustin
Status: newassigned

comment:17 by Aymeric Augustin, 12 years ago

Needs tests: set
Status: assignednew

comment:18 by Aymeric Augustin, 12 years ago

Needs tests: unset
Triage Stage: AcceptedReady 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 Claude Paroz, 12 years ago

I think this might be useful and does not add so much code, after all. +1

comment:20 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: newclosed

In 20a91cce04c72bc8c64a1c43b7398edac7b709cc:

Fixed #17037 -- Added a --all option to diffsettings.

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