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

-- 
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/047.026c6e81e4b7493d1b58446112dae841%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to