[Django] #26190: Return final management command result from call_command

53 views
Skip to first unread message

Django

unread,
Feb 9, 2016, 3:56:14 AM2/9/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New | Status: new
feature |
Component: Core | Version: master
(Management commands) |
Severity: Normal | Keywords:
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-------------------------------------+-------------------------------------
Currently, the result returned from the `handle` method of a management
command is directed by default to the console in the `execute` method by
writing to `self.stdout`, but it is not returned from the `execute`
method, so `call_command` does not receive it either.

I would suggest to adapt this behavior and also return this output from
`execute` (and consequently by `call_command` so we can easily get access
to this result from `call_command`). The behavior when calling the command
by the command line would be unchanged.

I even thought about not writing this result to `self.stdout` when the
command is called by `call_command`, but this would be backwards
incompatible and I don't see a good deprecation path for this.

--
Ticket URL: <https://code.djangoproject.com/ticket/26190>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 10, 2016, 9:42:35 AM2/10/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by timgraham):

Would this be an alternative to the currently documented method of:
{{{
with open('/path/to/command_output') as f:
management.call_command('dumpdata', stdout=f)
}}}
or is there some other difference?

--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:1>

Django

unread,
Feb 10, 2016, 5:04:40 PM2/10/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by claudep):

Only the return value of the command `handle()` method would be returned
from `call_command`.

In the current Django commands, only the following are returning some
content: diffsettings, sqlflush, sqlmigrate, sqlsequencereset,
changepassword (success message), findstatic. Other commands are calling
`self.stdout.write` during the processing of the command.

To get all the content output by a command, you still have to provide a
catcher in the sdtout argument as you mentioned.

--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:2>

Django

unread,
Feb 10, 2016, 6:29:40 PM2/10/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Unreviewed => Accepted


Comment:

I guess I don't have any objections other than I always found the return
value of `handle()` to be somewhat inconsistent and ill-defined as to when
that should be preferred instead of having the `handle()` method itself do
the logging.

--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:3>

Django

unread,
Feb 13, 2016, 12:22:55 PM2/13/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/6139 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:4>

Django

unread,
Feb 22, 2016, 3:57:51 PM2/22/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: new
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by timgraham):

* stage: Accepted => Ready for checkin


--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:5>

Django

unread,
Feb 23, 2016, 3:13:07 AM2/23/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: closed

Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Claude Paroz <claude@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"b46c0ea6c87f006f9ef0ccc5d8c0fa2445fb4156" b46c0ea6]:
{{{
#!CommitTicketReference repository=""
revision="b46c0ea6c87f006f9ef0ccc5d8c0fa2445fb4156"
Fixed #26190 -- Returned handle() result from call_command

Thanks Tim Graham for the review.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:6>

Django

unread,
Feb 23, 2016, 3:13:08 AM2/23/16
to django-...@googlegroups.com
#26190: Return final management command result from call_command
-------------------------------------+-------------------------------------
Reporter: claudep | Owner: nobody
Type: New feature | Status: closed
Component: Core (Management | Version: master
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage: Ready for
| checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Claude Paroz <claude@…>):

In [changeset:"269b5f262cef88cb595b21a76e707b41ee4ed627" 269b5f2]:
{{{
#!CommitTicketReference repository=""
revision="269b5f262cef88cb595b21a76e707b41ee4ed627"
Used call_command return value in staticfiles tests

Refs #26190.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26190#comment:7>

Reply all
Reply to author
Forward
0 new messages