#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.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.9d587e57405bd9e86a095e57ac7a658c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to