incr/decr returns 0 instead of None when can't connect to server
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.
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_
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.
Updated _incrdecr code and documentation and committed to github. Thanks!