summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2014-01-02 20:43:45 +0100
committerClaude Paroz <claude@2xlibre.net>2014-01-02 20:47:40 +0100
commitaaf5b3e7aad6fc8250143655854cc03c3b0a68c8 (patch)
tree39d45badbbd9f59cd5ebe1ef80b7f7ae1013ee67
parent7f110e7959a11608ba2714e563d67b2cdf61049c (diff)
Moved django.setup() to ManagementUtility
In get_commands, setup() might already have been called, for example when the management command is called through call_command. Moving setup() to ManagementUtility so as it is only called when the command is run from command line.
-rw-r--r--django/core/management/__init__.py10
1 files changed, 6 insertions, 4 deletions
diff --git a/django/core/management/__init__.py b/django/core/management/__init__.py
index 5966d8929e..34597bfa5f 100644
--- a/django/core/management/__init__.py
+++ b/django/core/management/__init__.py
@@ -115,10 +115,6 @@ def get_commands():
# settings, like startproject or help.
app_names = []
else:
- # Setup Django outside of the try/except block to avoid catching
- # ImproperlyConfigured errors that aren't caused by the absence of
- # a settings module.
- django.setup()
app_configs = apps.get_app_configs()
app_names = [app_config.name for app_config in app_configs]
@@ -390,6 +386,12 @@ class ManagementUtility(object):
pass # Ignore any option errors at this point.
try:
+ django.setup()
+ except ImproperlyConfigured:
+ # Some commands are supposed to work without configured settings
+ pass
+
+ try:
subcommand = self.argv[1]
except IndexError:
subcommand = 'help' # Display help if no arguments were given.