3 | | It's not that an error should be raised from nothing. It's that `ValueError` should be raised instead of `LibraryValueNotFoundException`. If you look at the links to the code I provided, the `delta < 0` code path isn't inside the try-except block a line later where that conversion takes place for the `delta >= 0` case. Please look, and you will see what I mean. This would just affect backends that derive from `BaseMemcachedCache`. |
| 3 | It's not that an error should be raised from nothing. It's that `ValueError` should be raised instead of `LibraryValueNotFoundException` (or returning `None`) when a key is missing. If you look at the links to the code I provided, the `delta < 0` code path isn't inside the try-except block a line later where that conversion takes place for the `delta >= 0` case. This would affect only some backends that derive from `BaseMemcachedCache`. I'm including the `incr()` method in full below to make it easier to see. The comment below has more details: |
| 4 | |
| 5 | {{{#!python |
| 6 | def incr(self, key, delta=1, version=None): |
| 7 | key = self.make_key(key, version=version) |
| 8 | # memcached doesn't support a negative delta |
| 9 | if delta < 0: |
| 10 | return self._cache.decr(key, -delta) |
| 11 | try: |
| 12 | val = self._cache.incr(key, delta) |
| 13 | |
| 14 | # python-memcache responds to incr on non-existent keys by |
| 15 | # raising a ValueError, pylibmc by raising a pylibmc.NotFound |
| 16 | # and Cmemcache returns None. In all cases, |
| 17 | # we should raise a ValueError though. |
| 18 | except self.LibraryValueNotFoundException: |
| 19 | val = None |
| 20 | if val is None: |
| 21 | raise ValueError("Key '%s' not found" % key) |
| 22 | return val |
| 23 | }}} |