diff options
| author | Claude Paroz <claude@2xlibre.net> | 2014-06-14 18:12:43 +0200 |
|---|---|---|
| committer | Claude Paroz <claude@2xlibre.net> | 2014-06-14 18:53:33 +0200 |
| commit | 5949c2118d7cc7cffe86cd9db1820b186b88bfc0 (patch) | |
| tree | ac8ce95ec3b35da70506328dd64b0d25dd2aed8d /django | |
| parent | 2ca5fc55b0a0b18ce4f060ee999ef355b5ceb0a3 (diff) | |
Restored command error behavior when called from command line
Refs #19973.
Diffstat (limited to 'django')
| -rw-r--r-- | django/core/management/base.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/django/core/management/base.py b/django/core/management/base.py index fbffc89786..b61d0b9b77 100644 --- a/django/core/management/base.py +++ b/django/core/management/base.py @@ -52,11 +52,14 @@ class CommandParser(ArgumentParser): # Catch missing argument for a better error message if (hasattr(self.cmd, 'missing_args_message') and not (args or any([not arg.startswith('-') for arg in args]))): - raise CommandError("Error: %s" % self.cmd.missing_args_message) + self.error(self.cmd.missing_args_message) return super(CommandParser, self).parse_args(args, namespace) def error(self, message): - raise CommandError("Error: %s" % message) + if self.cmd._called_from_command_line: + super(CommandParser, self).error(message) + else: + raise CommandError("Error: %s" % message) def handle_default_options(options): @@ -208,6 +211,7 @@ class BaseCommand(object): args = '' # Configuration shortcuts that alter various logic. + _called_from_command_line = False can_import_settings = True output_transaction = False # Whether to wrap the output in a "BEGIN; COMMIT;" leave_locale_alone = False @@ -338,6 +342,7 @@ class BaseCommand(object): to stderr. If the ``--traceback`` option is present or the raised ``Exception`` is not ``CommandError``, raise it. """ + self._called_from_command_line = True parser = self.create_parser(argv[0], argv[1]) if self.use_argparse: |
