#13760 closed Cleanup/optimization (fixed)
Management commands should not specify the default value twice
Reported by: | Paul McMillan | Owned by: | nobody |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.2 |
Severity: | Normal | Keywords: | |
Cc: | 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
Many of the management commands have a code pattern that seems likely to invite errors:
In the base of the Command class, they define options, including default values like this:
class Command(BaseCommand): option_list = BaseCommand.option_list + ( make_option('--format', default='json', dest='format', help='Specifies the output serialization format for fixtures.'),
Then later on in the handle method, they get the option value, specifying a new default value if the option is not found, like this:
def handle(self, *app_labels, **options): format = options.get('format','json')
This second default value is an error. Using optparse means that we are certain to receive a value for each option (it defaults to None). Using options.get() with a default value is redundant. Trying to get a non-existent option should throw an error, not return a default value.
Most of the management commands need this cleanup.
Attachments (3)
Change History (9)
comment:1 by , 15 years ago
Triage Stage: | Unreviewed → Accepted |
---|
by , 14 years ago
Attachment: | remove-dupe-defaults.diff added |
---|
comment:3 by , 14 years ago
Severity: | → Normal |
---|---|
Type: | → Cleanup/optimization |
comment:4 by , 13 years ago
Easy pickings: | unset |
---|---|
Has patch: | set |
Triage Stage: | Accepted → Ready for checkin |
UI/UX: | unset |
Remove duplicated default option values.