Handle ints passed to bool_from_string

Bug #1178760 reported by Rick Harris
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo-incubator
Fix Released
Undecided
Rick Harris

Bug Description

Nova and Oslo have two slightly different versions of `bool_from_string`.

For Nova, the int 1 and int 0 become True and False respectively.

For Oslo, both return False. (There are no tests defining this behavior in Oslo, so the official behavior is undefined).

Admittedly it's subjective, but Nova's behavior feels more correct here.

(Aside: Nova also has the behavior that string '2' is True whereas in Oslo it's False.

Again, Nova's behavior feels more correct, but given that, unlike the int case, Oslo has tests which *define* this as correct, it's probably better to hold onto the existing behavior.)

So the proposal here is to:

Teach Oslo's bool_from_string how to deal with ints like Nova's version.
Hold onto Oslo's dubious way of dealing with numbers as strings.

Changed in oslo:
assignee: nobody → Rick Harris (rconradharris)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to oslo-incubator (master)

Fix proposed to branch: master
Review: https://review.openstack.org/28856

Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo-incubator (master)

Reviewed: https://review.openstack.org/28856
Committed: http://github.com/openstack/oslo-incubator/commit/d9b0719f02433b243a20fe705af4799c619f4e28
Submitter: Jenkins
Branch: master

commit d9b0719f02433b243a20fe705af4799c619f4e28
Author: Rick Harris <email address hidden>
Date: Fri May 10 23:07:27 2013 +0000

    Handle ints passed to `boolean_from_string`

    The existing code would return True for '1' but False for int(1),
    unlike Nova's version which would return True for both inputs.

    Nova's version feels safer (i.e. it will do the most-likely-correct
    thing if an int is passed in), so this patch changes
    Openstack-Common's version to match.

    Note that this patch does not make Openstack-Common's
    `boolean_from_string` match Nova's `bool_from_string` exactly though.
    Nova's version would return True for both '42' and 42, while
    Openstack-Common's returns False. Though Nova's version, again, seems
    safer, the presence of unit-tests in Openstack-Common asserting the
    defined-correctness of this behavior makes me reluctant to change it.

    Fixes bug 1178760

    Change-Id: I8b2a31c4852884187bcbda3a4e78c8513b1bb8c8

Changed in oslo:
status: In Progress → Fix Committed
Thierry Carrez (ttx)
Changed in oslo:
milestone: none → havana-1
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in oslo:
milestone: havana-1 → 2013.2
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.