Setting/Getting boolean values ValueError

Bug #1479184 reported by Carlos Sanchez on 2015-07-29
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Memcached

Bug Description

In Python Memcached 1.56 (w/ six-1.9.0 & Python 2.7.10)


cache.set('foo', False)

generates a ValueError: invalid literal for int() with base 10: 'False'

line 1235

When the method _val_to_store_info is called the path code that it is followed with a boolean is

       elif isinstance(val, int):
            flags |= Client._FLAG_INTEGER
            val = str(val)
            if six.PY3:
                val = val.encode('ascii')
            # force no attempt to compress this silly string.
            min_compress_len = 0

Since the flags bits have been set to an integer, the boolean value is changed to a string ('False'). So in the method _recv_value the code tries to change that string to an int which fails .

Carlos Sanchez (papachoco) wrote :

In In Python Memcached 1.54

the original code in _val_to_store_info is

elif isinstance(val, int):
            flags |= Client._FLAG_INTEGER
            val = "%d" % val
            # force no attempt to compress this silly string.
            min_compress_len = 0

the issue also affect when checking for long values

To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers