[Django] #24518: OptionParser verbosity not cast to int (Python3)

15 views
Skip to first unread message

Django

unread,
Mar 20, 2015, 9:16:57 PM3/20/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
--------------------------------------------+----------------------
Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: new
Component: Core (Management commands) | Version: 1.8rc1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 1 | UI/UX: 0
--------------------------------------------+----------------------
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')
}}}

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

Django

unread,
Mar 20, 2015, 10:33:00 PM3/20/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: assigned
Component: Core (Management | Version: 1.8rc1
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by jthi3rry):

* 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>

Django

unread,
Mar 21, 2015, 5:15:09 AM3/21/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: closed

Component: Core (Management | Version: 1.8rc1
commands) |
Severity: Normal | Resolution: wontfix
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* 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>

Django

unread,
Apr 3, 2015, 3:17:14 PM4/3/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------

Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: new
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bkonkle):

* 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>

Django

unread,
Apr 3, 2015, 3:39:14 PM4/3/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: closed

Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution: fixed
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bkonkle):

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


Comment:

I found the problem:

https://github.com/django/django/commit/f17b24e407385eb18651bf023a187347aa9c1f75#commitcomment-10567852

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>

Django

unread,
Apr 3, 2015, 3:50:49 PM4/3/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------

Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: new
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bkonkle):

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


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

Django

unread,
Apr 3, 2015, 5:03:35 PM4/3/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------

Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: new
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by bkonkle):

* 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>

Django

unread,
Apr 3, 2015, 7:22:25 PM4/3/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------

Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: new
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Apr 4, 2015, 4:36:11 AM4/4/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry
Type: Bug | Status: closed

Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* 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>

Django

unread,
Apr 4, 2015, 8:09:07 PM4/4/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry

Type: Bug | Status: closed
Component: Core (Management | Version: 1.8
commands) |
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
Apr 5, 2015, 2:44:18 PM4/5/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry

Type: Bug | Status: closed
Component: Core (Management | Version: 1.8
commands) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by claudep):

* resolution: needsinfo => worksforme


--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:10>

Django

unread,
May 11, 2015, 6:40:29 AM5/11/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry

Type: Bug | Status: closed
Component: Core (Management | Version: 1.8
commands) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 11, 2015, 4:37:01 PM5/11/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry

Type: Bug | Status: closed
Component: Core (Management | Version: 1.8
commands) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Django

unread,
May 11, 2015, 5:58:05 PM5/11/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry

Type: Bug | Status: closed
Component: Core (Management | Version: 1.8
commands) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by jthi3rry):

This ticket was created for 1.8 rc1

--
Ticket URL: <https://code.djangoproject.com/ticket/24518#comment:13>

Django

unread,
May 12, 2015, 3:12:28 AM5/12/15
to django-...@googlegroups.com
#24518: OptionParser verbosity not cast to int (Python3)
-------------------------------------+-------------------------------------
Reporter: jthi3rry | Owner: jthi3rry

Type: Bug | Status: closed
Component: Core (Management | Version: 1.8
commands) | Resolution:
Severity: Normal | worksforme
Keywords: | Triage Stage:
| Unreviewed

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------

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>

Reply all
Reply to author
Forward
0 new messages