python-memcache delete() does not distinguish between DELETED and NOT_FOUND

Bug #471727 reported by Forest
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Python Memcached
Fix Released
Medium
Sean Reifschneider

Bug Description

The memcached protocol reports DELETED or NOT_FOUND on delete, depending on whether the key was present to begin with. memcache.Client.delete() returns 1 regardless of what the server returned, preventing the calling code from using this feature of memcached.

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

This may have to be done as a separate function, unless it can be implemented such that it won't act in unexpected ways for existing users.

Changed in python-memcached:
status: New → Confirmed
Changed in python-memcached:
importance: Undecided → Medium
assignee: nobody → Sean Reifschneider (jafo)
Revision history for this message
Sean Reifschneider (jafo) wrote :

I changed the code in the delete so that it explicitly looks at NOT_FOUND and DELETED, but I do treat them the same, since NOT_FOUND could be the result of an expiration. But I did also add debugging if the result is not one of those two. The current API I think best fits with treating them both as "successful" return codes, per the documentation, so if distinguishing between NOT_FOUND and DELETED is required it should probably be a different function in the API.

I also added a test to make sure that a delete works.

Changed in python-memcached:
status: Confirmed → Fix Committed
Revision history for this message
Forest (foresto) wrote :

I noticed the problem in the first place because I wanted to implement a python-openid store using memecached. (OpenID associations and nonces need not be kept forever, so the possibility of an expired item is a non-issue here.) The removeAssociation() method of the store interface returns whether or not the given association existed, so implementing it atop memcached requires a memcache client whose delete() call distinguishes NOT_FOUND and DELETED to calling code.

More generally, I think it's a good idea not to throw away information when putting an API around memcached. One never knows in advance what classes of application might have use for that information.

Changed in python-memcached:
status: Fix Committed → Fix Released
Revision history for this message
Sean Reifschneider (jafo) wrote :

I agree with what you are saying about not throwing away things needlessly, however the API was designed to fail silently in most cases and that's something we have to live with. I'd encourage a resolution to this that provides the required information without breaking existing code.

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.