diff options
| author | Adam Johnson <me@adamj.eu> | 2020-04-14 08:56:16 +0100 |
|---|---|---|
| committer | Mariusz Felisiak <felisiak.mariusz@gmail.com> | 2020-04-14 13:22:47 +0200 |
| commit | 8e8c3f964e23e669fc563a74750e51abba4c2e3a (patch) | |
| tree | 35a0060e2aebb7f97cc7eff303c2e8c812999787 /docs/howto | |
| parent | 6cad911674dc067ffab44eea4f5c8170fa0a89b1 (diff) | |
Refs #29501 -- Allowed customizing exit status for management commands.
Diffstat (limited to 'docs/howto')
| -rw-r--r-- | docs/howto/custom-management-commands.txt | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/docs/howto/custom-management-commands.txt b/docs/howto/custom-management-commands.txt index ec83dda381..77c4c61e8c 100644 --- a/docs/howto/custom-management-commands.txt +++ b/docs/howto/custom-management-commands.txt @@ -340,7 +340,7 @@ Rather than implementing :meth:`~BaseCommand.handle`, subclasses must implement Command exceptions ------------------ -.. exception:: CommandError +.. exception:: CommandError(returncode=1) Exception class indicating a problem while executing a management command. @@ -348,8 +348,14 @@ If this exception is raised during the execution of a management command from a command line console, it will be caught and turned into a nicely-printed error message to the appropriate output stream (i.e., stderr); as a result, raising this exception (with a sensible description of the error) is the preferred way -to indicate that something has gone wrong in the execution of a command. +to indicate that something has gone wrong in the execution of a command. It +accepts the optional ``returncode`` argument to customize the exit status for +the management command to exit with, using :func:`sys.exit`. If a management command is called from code through :func:`~django.core.management.call_command`, it's up to you to catch the exception when needed. + +.. versionchanged:: 3.1 + + The ``returncode`` argument was added. |
