Integer(0) will return 0 even 0 is not in the range specified

Bug #1416212 reported by Longjie_Cao
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
oslo.config
Fix Released
Undecided
Davanum Srinivas (DIMS)

Bug Description

THe line in Integer.__call__ should compare None , not False:
  def __call__(self, value):
        if not isinstance(value, int):
          ....

        if value:
            self._check_range(value)

        return value

Should be modified as:

  def __call__(self, value):
        if not isinstance(value, int):
          ....

        if value is not None:
            self._check_range(value)

        return value

How to reproduce the problem:
>>> from oslo.config import types
>>> Test1 = types.Integer(3,6)
>>> Test1(0)
0

After modification:
>>> from oslo.config import types
>>> Test1 = types.Integer(3,6)
>>> Test1(0)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/lib/python2.7/dist-packages/oslo/config/types.py", line 129, in __call__
    self._check_range(value)
  File "/usr/lib/python2.7/dist-packages/oslo/config/types.py", line 136, in _check_range
    self.min)
ValueError: Should be greater than or equal to 3

Revision history for this message
Longjie_Cao (grasson1101) wrote :
Changed in oslo.config:
assignee: nobody → Davanum Srinivas (DIMS) (dims-v)
status: New → In Progress
Revision history for this message
OpenStack Infra (hudson-openstack) wrote : Fix merged to oslo.config (master)

Reviewed: https://review.openstack.org/151940
Committed: https://git.openstack.org/cgit/openstack/oslo.config/commit/?id=0366f880d5222251ce4b6833fa556d11d1e47229
Submitter: Jenkins
Branch: master

commit 0366f880d5222251ce4b6833fa556d11d1e47229
Author: Davanum Srinivas <email address hidden>
Date: Sun Feb 1 15:00:48 2015 -0500

    Better check for integer range to account for 0

    We should be using "if value is not None" to better check
    for the condition where the value is 0 and 0 is not in the
    valid range.

    Co-Authored-By: Longjie_Cao <email address hidden>
    Closes-Bug: #1416212
    Change-Id: Ie5c81f1916e301619955364b040bdc7a9275e29c

Changed in oslo.config:
status: In Progress → Fix Committed
Changed in oslo.config:
milestone: none → 1.7.0
status: Fix Committed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Bug attachments

Remote bug watches

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