The problem comes from this line:
{{{
parser.add_option('-v', '--verbosity', action='store', dest='verbosity',
default='1',
type='choice', choices=['0', '1', '2', '3'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose
output, 3=very verbose output')
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24518>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* status: new => assigned
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
Old description:
> With Python3, when not using argparse for a management command, the
> verbosity option uses a type=choice, which leads to a `TypeError:
> unorderable types: str() > int()` in
> `django/core/management/commands/test.py` at line 65 (`if
> options['verbosity'] > 0`)
>
> The problem comes from this line:
> {{{
> parser.add_option('-v', '--verbosity', action='store', dest='verbosity',
> default='1',
> type='choice', choices=['0', '1', '2', '3'],
> help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose
> output, 3=very verbose output')
> }}}
New description:
With Python3, when not using argparse for a management command, the
verbosity option uses a type=choice, which leads to a `TypeError:
unorderable types: str() > int()` in
`django/core/management/commands/test.py` at line 65 (`if
options['verbosity'] > 0`)
The problem comes from this line in `django/core/management/base.py`:
{{{
parser.add_option('-v', '--verbosity', action='store', dest='verbosity',
default='1',
type='choice', choices=['0', '1', '2', '3'],
help='Verbosity level; 0=minimal output, 1=normal output, 2=verbose
output, 3=very verbose output')
}}}
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:1>
* status: assigned => closed
* resolution: => wontfix
Comment:
I'm not sure we want to change that. If you look at Django management
commands in pre-1.8 versions, you'll read many `self.verbosity =
int(options.get('verbosity'))` or `if int(options['verbosity']) > 0:`
patterns. The future is definitely using `argparse`, so if for any reason
you still want to keep using `optparse`, you should continue to cast the
result of the `verbosity` option to `int`.
Your proposed patch would remove the option list checking of `verbosity`,
which would be slightly backwards incompatible.
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:2>
* status: closed => new
* version: 1.8rc1 => 1.8
* resolution: wontfix =>
Comment:
I'm running into this when trying to run core Django management commands
in 1.8 on Python 3.4. 'makemigrations' and 'test' are two examples. I
simply cannot run these management commands in Python 3.4.
Here's a screenshot: http://knkl.us/11vVb
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
I found the problem:
Verbosity used to be set like this:
`self.verbosity = int(options.get('verbosity'))`
Now it's set like this:
`self.verbosity = options.get('verbosity')`
There's no int conversion in 1.8 like there was in 1.7, a change made
during the conversion to argparse. I assume the fix would be to go back to
converting to int. I'll work up a pull request on Github.
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:4>
* status: closed => new
* resolution: fixed =>
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:5>
* has_patch: 0 => 1
Comment:
Pull request submitted here:
https://github.com/django/django/pull/4449/files
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:6>
Comment (by timgraham):
`manage.py` works for me using the tutorial and Python 3.4.3. Are you sure
this isn't caused by a third-party library somehow? Maybe it's worth
fixing for backwards compatibility purposes, but I'd like to understand
the reason for it.
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:7>
* status: new => closed
* resolution: => needsinfo
Comment:
I can only reproduce the issue when calling `call_command` and passing a
string to `verbosity` which I would classify as a user programming error,
not a bug in Django. When using the command line directly, `argparse` is
converting to integer for us.
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:8>
Comment (by bkonkle):
You are absolutely right. I discovered the real origin of the issue - an
older version of django-configurations was adding an option to the
BaseCommand.option_list, which was causing it to use optparse for all
management commands rather than argparse. None of the add_arguments()
methods were being called at all. I updated django-configurations, and the
problem is now solved. Sorry for the trouble!
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:9>
* resolution: needsinfo => worksforme
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:10>
Comment (by blueyed):
For reference: I am suggesting to use `int` for `verbosity` also with the
old parser for consistency: see #24769 (which has a patch/PR).
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:11>
Comment (by claudep):
I would have supported this request if this had popped up before 1.8
final. Now I'm reluctant to change this in a stable release. And then, if
we don't do it for 1.8, it makes not much sense to do it for 1.9 either.
But I'll let someone else take the final decision.
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:12>
Comment (by jthi3rry):
This ticket was created for 1.8 rc1
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:13>
Comment (by claudep):
Sorry, my bad. I admit that the scenario of third-party apps monkey-
patching core commands was not a use case I considered when writing the
compatibility layer.
--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:14>