Comment 2 for bug 832131

Revision history for this message
Pete-alex-harris (pete-alex-harris) wrote :

Patch attached.

My use case:

  * You want to delete a load of keys, and you know they all begin with the same prefix, with various suffixes that you have in a list. You'd use delete_multi(suffixes, key_prefix=prefix).
  * What if one of the keys to delete is just the bare prefix itself? Then one of the suffixes is the empty string.

But:

  * _map_and_prefix_keys() will call check_key() with each of the suffixes as "key", and the length of the prefix as "key_extra_len".
  * check_key() will fail if "key" is an empty string, and it will fail with an error that suggests that the key is None (which it isn't).
  * check_key() only needs to fail if "key" is an empty string and "key_extra_len" == 0, because if key_extra_len > 0 then the key is not empty.

So this patch allows the case where the set of keys to be deleted with delete_multi() includes the key that is key_prefix itself (one of the key suffixes is empty).