Wrong comparisons with "in" operator

Bug #1248443 reported by Alvaro Lopez
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
OpenStack Compute (nova)
Fix Released
Undecided
Alvaro Lopez

Bug Description

In the code there are several comparisons using the "in" operator to check if a value occurs in a tuple with only one element, like:

    if a in ("foo"):
        do_something()

This comparison is wrong, since that is not a tuple with one element [1], therefore if the variable "a" had a value of "f" it will match.

[1] http://docs.python.org/2/tutorial/datastructures.html#tuples-and-sequences

Alvaro Lopez (aloga)
Changed in nova:
assignee: nobody → Alvaro Lopez (aloga)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix proposed to nova (master)

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

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

Reviewed: https://review.openstack.org/55362
Committed: http://github.com/openstack/nova/commit/47c95694e93b361e3b0738afac8e724557a36c8a
Submitter: Jenkins
Branch: master

commit 47c95694e93b361e3b0738afac8e724557a36c8a
Author: Alvaro Lopez Garcia <email address hidden>
Date: Wed Nov 6 09:29:05 2013 +0100

    Fix "in" comparisons with one element tuples

    A single value enclosed in parentheses is not a tuple (it needs a comma
    after the element) therefore the comparisons like 'if foo in ("bar")'
    are wrong.

    Closes-Bug: #1248443
    Change-Id: I29a2227c9d83efc17ecfacc86d507d75edd4eaca

Changed in nova:
status: In Progress → Fix Committed
Changed in nova:
milestone: none → icehouse-1
Thierry Carrez (ttx)
Changed in nova:
status: Fix Committed → Fix Released
Thierry Carrez (ttx)
Changed in nova:
milestone: icehouse-1 → 2014.1
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.