[Django] #25483: [doc] Using call_command() should pass positional argument as str() instead of int()

39 views
Skip to first unread message

Django

unread,
Sep 28, 2015, 11:22:49 PM9/28/15
to django-...@googlegroups.com
#25483: [doc] Using call_command() should pass positional argument as str() instead
of int()
-------------------------------+--------------------
Reporter: mrkschan | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.8
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
Since argparse is adopted, int() argument should be passed as str() and
let argparse to handle it. This is better mentioned in the doc.

See below example:

{{{
# management/commands/callme.py
from django.core.management.base import BaseCommand, CommandError

class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument('poll_id', nargs='+', type=int)

def handle(self, *args, **options):
for poll_id in options['poll_id']:
self.stdout.write('%d' % poll_id)


# python manage.py shell
>>> from django.core.management import call_command
>>> call_command('callme', 1, 2, 3)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "/home/mrkschan/tmp/tcallcommand/env/local/lib/python2.7/site-
packages/django/core/management/__init__.py", line 109, in call_command
defaults = parser.parse_args(args=args)
File "/home/mrkschan/tmp/tcallcommand/env/local/lib/python2.7/site-
packages/django/core/management/base.py", line 64, in parse_args
return super(CommandParser, self).parse_args(args, namespace)
File "/usr/lib/python2.7/argparse.py", line 1690, in parse_args
args, argv = self.parse_known_args(args, namespace)
File "/usr/lib/python2.7/argparse.py", line 1722, in parse_known_args
namespace, args = self._parse_known_args(args, namespace)
File "/usr/lib/python2.7/argparse.py", line 1763, in _parse_known_args
option_tuple = self._parse_optional(arg_string)
File "/usr/lib/python2.7/argparse.py", line 2050, in _parse_optional
if not arg_string[0] in self.prefix_chars:
TypeError: 'int' object has no attribute '__getitem__'
>>> call_command('callme', '1', '2', '3')
1
2
3
}}}

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

Django

unread,
Sep 29, 2015, 3:04:24 AM9/29/15
to django-...@googlegroups.com
#25483: [doc] Using call_command() should pass positional argument as str() instead
of int()
-------------------------------------+-------------------------------------
Reporter: mrkschan | Owner: nobody
Type: | Status: new
Cleanup/optimization |
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 claudep):

* needs_better_patch: => 0
* component: Documentation => Core (Management commands)
* needs_tests: => 0
* version: 1.8 => master
* needs_docs: => 0
* type: Uncategorized => Cleanup/optimization
* stage: Unreviewed => Accepted


Comment:

I think we could force all `args` to text before passing them to
`parse_args`.

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

Django

unread,
Oct 3, 2015, 4:03:03 AM10/3/15
to django-...@googlegroups.com
#25483: [doc] Using call_command() should pass positional argument as str() instead
of int()
-------------------------------------+-------------------------------------
Reporter: mrkschan | Owner: nobody

Type: | Status: new
Cleanup/optimization |
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


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

Django

unread,
Oct 3, 2015, 8:37:06 AM10/3/15
to django-...@googlegroups.com
#25483: [doc] Using call_command() should pass positional argument as str() instead
of int()
-------------------------------------+-------------------------------------
Reporter: mrkschan | Owner: nobody

Type: | Status: new
Cleanup/optimization |
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/25483#comment:3>

Django

unread,
Oct 3, 2015, 8:40:36 AM10/3/15
to django-...@googlegroups.com
#25483: call_command() should pass positional argument as str() instead of int()
-------------------------------------+-------------------------------------
Reporter: mrkschan | Owner: nobody

Type: | Status: new
Cleanup/optimization |
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
-------------------------------------+-------------------------------------

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

Django

unread,
Oct 3, 2015, 8:41:19 AM10/3/15
to django-...@googlegroups.com
#25483: call_command() should pass positional argument as str() instead of int()
-------------------------------------+-------------------------------------
Reporter: mrkschan | Owner: nobody
Type: | Status: closed

Cleanup/optimization |
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:"3f22e83e90bc2eeea5f65858660385a34fbf5486" 3f22e83]:
{{{
#!CommitTicketReference repository=""
revision="3f22e83e90bc2eeea5f65858660385a34fbf5486"
Fixed #25483 -- Allowed passing non-string arguments to call_command

Thanks KS Chan for the report and Tim Graham for the review.
}}}

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

Reply all
Reply to author
Forward
0 new messages