Commit aaf5b3e7 authored by Claude Paroz's avatar Claude Paroz
Browse files

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.
parent 7f110e79
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -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: