mirror of
https://github.com/django/django.git
synced 2024-11-29 22:56:46 +01:00
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.
This commit is contained in:
parent
7f110e7959
commit
aaf5b3e7aa
@ -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]
|
||||
|
||||
@ -389,6 +385,12 @@ class ManagementUtility(object):
|
||||
except: # Needed because parser.parse_args can raise SystemExit
|
||||
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:
|
||||
|
Loading…
Reference in New Issue
Block a user