From fc92c6b5000179145ec633a70f380a0a109381c3 Mon Sep 17 00:00:00 2001 From: Claude Paroz Date: Thu, 29 Sep 2016 15:05:23 +0200 Subject: [PATCH] Removed unneeded no_settings_commands hardcoded list Thanks Tim Graham for the review. --- django/core/management/__init__.py | 9 --------- django/core/management/base.py | 7 ++++++- django/core/management/templates.py | 3 ++- 3 files changed, 8 insertions(+), 11 deletions(-) diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py index a49ffdd3b8..7b667e7c8f 100644 --- a/django/core/management/__init__.py +++ b/django/core/management/__init__.py @@ -306,19 +306,10 @@ class ManagementUtility(object): except CommandError: pass # Ignore any option errors at this point. - no_settings_commands = [ - 'help', 'version', '--help', '--version', '-h', - 'startapp', 'startproject', 'compilemessages', - ] - try: settings.INSTALLED_APPS except ImproperlyConfigured as exc: self.settings_exception = exc - # A handful of built-in management commands work without settings. - # Load the default settings -- where INSTALLED_APPS is empty. - if subcommand in no_settings_commands: - settings.configure() if settings.configured: # Start the auto-reloading dev server even if the code is broken. diff --git a/django/core/management/base.py b/django/core/management/base.py index 3726d42150..6aaf2fc4bb 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -303,7 +303,12 @@ class BaseCommand(object): self.stderr.write('%s: %s' % (e.__class__.__name__, e)) sys.exit(1) finally: - connections.close_all() + try: + connections.close_all() + except ImproperlyConfigured: + # Ignore if connections aren't setup at this point (e.g. no + # configured settings). + pass def execute(self, *args, **options): """ diff --git a/django/core/management/templates.py b/django/core/management/templates.py index fd957fbabf..466ea935d8 100644 --- a/django/core/management/templates.py +++ b/django/core/management/templates.py @@ -11,6 +11,7 @@ import tempfile from os import path import django +from django.conf import settings from django.core.management.base import BaseCommand, CommandError from django.core.management.utils import handle_extensions from django.template import Context, Engine @@ -119,9 +120,9 @@ class TemplateCommand(BaseCommand): }), autoescape=False) # Setup a stub settings environment for template rendering - from django.conf import settings if not settings.configured: settings.configure() + django.setup() template_dir = self.handle_template(options['template'], base_subdir)