Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow delete() to change the "expected" param. #170

Closed
felixxm opened this issue Nov 14, 2019 · 0 comments · Fixed by #190
Closed

Allow delete() to change the "expected" param. #170

felixxm opened this issue Nov 14, 2019 · 0 comments · Fixed by #190

Comments

@felixxm
Copy link

felixxm commented Nov 14, 2019

Currently delete() calls _deletetouch() with [b'DELETED', b'NOT_FOUND']. We would like to have an option to pass lists of expected results and customize this behavior, because we don't treat passing a non existent key as a succeeded deletion (see related discussion).

ngnpope added a commit to ngnpope/python-memcached that referenced this issue Dec 30, 2023
The `delete()` command currently returns `1` if the response from the
server is either `'DELETED'` or `'NOT_FOUND'`. This differs from other
implementations, e.g. `pymemcache` and `pylibmc`, and doesn't seem to
make sense given that these are the only two documented return types
from the protocol for the delete command.

It seems that `delete()` was changed to explicitly consider both
responses as successful way back in 2010, but that change only seemed to
double down on the behavior that was being reported in the issue.
See https://bugs.launchpad.net/python-memcached/+bug/471727. The concern
was avoiding breaking backward compatibility.

It was possible to work around this by calling `_deletetouch()` and
passing in the `expected` responses, but that was broken by the change
to remove `time` in ab668ed.

To avoid issues with backward compatibility, I've added a `strict`
argument which can be enabled to return a non-successful response from
`delete()` for `'NOT_FOUND'`.

Further, making the change to interpret `'NOT_FOUND'` as `0` doesn't
cause any test failures. I've added an assertion to check deletion of a
non-existent key use both strict and non-strict.

Fixes linsomniac#170.
ngnpope added a commit to ngnpope/python-memcached that referenced this issue Jan 2, 2024
The `delete()` command currently returns `1` if the response from the
server is either `'DELETED'` or `'NOT_FOUND'`. This differs from other
implementations, e.g. `pymemcache` and `pylibmc`, and doesn't seem to
make sense given that these are the only two documented return types
from the protocol for the delete command.

It seems that `delete()` was changed to explicitly consider both
responses as successful way back in 2010, but that change only seemed to
double down on the behavior that was being reported in the issue.
See https://bugs.launchpad.net/python-memcached/+bug/471727. The concern
was avoiding breaking backward compatibility.

It was possible to work around this by calling `_deletetouch()` and
passing in the `expected` responses, but that was broken by the change
to remove `time` in ab668ed.

Making the change to interpret `'NOT_FOUND'` as `0` doesn't cause any
test failures, is consistent with the docstring which states that that
the command returns non-zero on success, and also brings consistency
with other implementations.

Fixes linsomniac#170.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant