[Django] #26294: call_command doesn't raise same errors from option parsing as running command

7 views
Skip to first unread message

Django

unread,
Feb 29, 2016, 10:41:00 AM2/29/16
to django-...@googlegroups.com
#26294: call_command doesn't raise same errors from option parsing as running
command
-----------------------------------+--------------------
Reporter: mbox | Owner: nobody
Type: Uncategorized | Status: new
Component: Testing framework | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-----------------------------------+--------------------
Minimal example:

management/commands/bug.py


{{{
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('-n', action='store', dest='number', type=int)

def handle(self, **options):
int(options['number'])

}}}


Execute as:

{{{
./manage.py bug -n nan

error: argument -n: invalid int value: 'nan'
}}}

Test using call_command:

{{{
call_command('bug', n='nan')
}}}

Raises a ValueError trying to convert {{{options['number']}}}

The core problem seems to be that kwargs to call_command aren't passed
through the argparse command processing in the way that *args is.

There's a work-around, which is to use the {{{ call_command('bug', '-n
nan') }}} format - perhaps this could be called out in the docs?

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

Django

unread,
Feb 29, 2016, 12:54:23 PM2/29/16
to django-...@googlegroups.com
#26294: call_command doesn't raise same errors from option parsing as running
command
--------------------------------------+------------------------------------
Reporter: mbox | Owner: nobody
Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
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 claudep):

* needs_better_patch: => 0
* component: Testing framework => Documentation
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

This could be clearer in the docs. Something like that?
{{{#!diff
diff --git a/docs/ref/django-admin.txt b/docs/ref/django-admin.txt
index 6a7752f..0a5de46 100644
--- a/docs/ref/django-admin.txt
+++ b/docs/ref/django-admin.txt
@@ -1763,10 +1763,11 @@ To call a management command from code use
``call_command``.
the name of the command to call.

``*args``
- a list of arguments accepted by the command.
+ a list of arguments accepted by the command and fed to the parser.

``**options``
- named options accepted on the command-line.
+ named options accepted on the command-line. Those will be directly
passed to
+ the command without triggering the argument parser.

Examples::
}}}

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

Django

unread,
Mar 12, 2016, 5:47:37 PM3/12/16
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
--------------------------------------+------------------------------------
Reporter: mbox | Owner: nobody

Type: Cleanup/optimization | Status: new
Component: Documentation | Version: master
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 timgraham):

* has_patch: 0 => 1


Comment:

Makes sense, Claude. I expanded that a bit with some examples:
[https://github.com/django/django/pull/6284 PR].

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

Django

unread,
Mar 14, 2016, 4:13:42 AM3/14/16
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
-------------------------------------+-------------------------------------
Reporter: mbox | Owner: nobody
Type: | Status: new
Cleanup/optimization |

Component: Documentation | Version: master
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 claudep):

* stage: Accepted => Ready for checkin


Comment:

Thanks for the nice worded patch.

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

Django

unread,
Mar 14, 2016, 8:29:38 AM3/14/16
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
-------------------------------------+-------------------------------------
Reporter: mbox | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
Component: Documentation | Version: master
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 Tim Graham <timograham@…>):

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


Comment:

In [changeset:"5695c142d282f4681a8d43bb55ec49f11f3fc40e" 5695c142]:
{{{
#!CommitTicketReference repository=""
revision="5695c142d282f4681a8d43bb55ec49f11f3fc40e"
Fixed #26294 -- Clarified call_command()'s handling of args and options.
}}}

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

Django

unread,
Mar 14, 2016, 8:29:46 AM3/14/16
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
-------------------------------------+-------------------------------------
Reporter: mbox | Owner: nobody

Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
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 Tim Graham <timograham@…>):

In [changeset:"7b2ee75745a5304b222b71b3273ff14a40da47f4" 7b2ee757]:
{{{
#!CommitTicketReference repository=""
revision="7b2ee75745a5304b222b71b3273ff14a40da47f4"
[1.9.x] Fixed #26294 -- Clarified call_command()'s handling of args and
options.

Backport of 5695c142d282f4681a8d43bb55ec49f11f3fc40e from master
}}}

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

Django

unread,
May 30, 2017, 5:15:44 PM5/30/17
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: nobody

Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
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 Tim Graham <timograham@…>):

In [changeset:"a30482a4b6e5d13e7325238fdc902fbca7e714f4" a30482a4]:
{{{
#!CommitTicketReference repository=""
revision="a30482a4b6e5d13e7325238fdc902fbca7e714f4"
Refs #26294 -- Fixed typo in docs/ref/django-admin.txt.
}}}

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

Django

unread,
May 30, 2017, 5:16:23 PM5/30/17
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
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 Tim Graham <timograham@…>):

In [changeset:"ceb6a64f2f5d8e4a5309d9558f89a6d1f0b6308d" ceb6a64f]:
{{{
#!CommitTicketReference repository=""
revision="ceb6a64f2f5d8e4a5309d9558f89a6d1f0b6308d"
[1.11.x] Refs #26294 -- Fixed typo in docs/ref/django-admin.txt.

Backport of a30482a4b6e5d13e7325238fdc902fbca7e714f4 from master
}}}

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

Django

unread,
May 30, 2017, 5:16:30 PM5/30/17
to django-...@googlegroups.com
#26294: Clarify call_command()'s handling of args and options
-------------------------------------+-------------------------------------
Reporter: Malcolm Box | Owner: nobody
Type: | Status: closed
Cleanup/optimization |
Component: Documentation | Version: master
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 Tim Graham <timograham@…>):

In [changeset:"4cb51412919a0aacdb26c87d409ab3afaf53ca18" 4cb51412]:
{{{
#!CommitTicketReference repository=""
revision="4cb51412919a0aacdb26c87d409ab3afaf53ca18"
[1.10.x] Refs #26294 -- Fixed typo in docs/ref/django-admin.txt.

Backport of a30482a4b6e5d13e7325238fdc902fbca7e714f4 from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/26294#comment:8>

Reply all
Reply to author
Forward
0 new messages