incr/decr returns 0 instead of None when can't connect to server

Bug #986046 reported by Ivan Virabyan
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Memcached
Fix Committed
Medium
Sean Reifschneider

Bug Description

Consider this code:

hits = cache.incr('hits')
if hits is None:
    hits = 1
    cache.set('hits', hits)
assert hits != 0

Variable 'hits' here must always be a positive integer. This works fine, but in vary rare cases variable 'hits' gets 0 value. I looked at the code, and found out, that incr/decr returns zero when it wasn't able to connect to the memcached:
        server, key = self._get_server(key)
        if not server:
            return 0

But when key doesn't exist, or there was a socket error while sending the command, return value is None.
This is very confusing. I can't distingish error result, from success increment of -1.
I think it'd be more appropriate to return None when there were connection errors.

Revision history for this message
Sean Reifschneider (jafo) wrote :

Updated _incrdecr code and documentation and committed to github. Thanks!

Changed in python-memcached:
status: New → Fix Committed
importance: Undecided → Medium
assignee: nobody → Sean Reifschneider (jafo)
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.