Opened 10 years ago

Closed 10 years ago

Last modified 7 years ago

#9626 closed (fixed)

Bug in Cache when calling has_key

Reported by: anonymous Owned by: nobody
Component: Core (Cache system) Version: 1.0
Severity: Keywords: cache, has_key, KeyError, locmem, del
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


File "/var/django/mydjangoapp/../mydjangoapp/stories/", line 5, in get_cached_num

if not cache.has_key(which):

File "/var/lib/python-support/python2.4/django/core/cache/backends/", line 99, in has_key

del self._cache[key]

KeyError: 'authors'

i do not think, its a bug in my code, when django tries to delete a item, for which i am checking if it even exists.

Change History (6)

comment:1 Changed 10 years ago by (none)

milestone: post-1.0

Milestone post-1.0 deleted

comment:2 Changed 10 years ago by Jacob

milestone: 1.1
Triage Stage: UnreviewedAccepted

comment:3 Changed 10 years ago by Malcolm Tredinnick

As far as I can see, this can only be caused by a thread race, since by the time the line of code in question is executed, we know the key was in the cache from a few lines earlier. I'm avoiding that, but this shouldn't be happening in normal operations, since the locmem cache isn't particularly appropriate for user between multiple threads (every other cache backend is better).

comment:4 Changed 10 years ago by Malcolm Tredinnick

Resolution: fixed
Status: newclosed

(In [9998]) Fixed #9626 -- Fixed a deletion race in the locmem cache.

comment:5 Changed 10 years ago by mrts

Malcolm, while you are at it, can you please take a look at #9644 as well? It's the same thing, only in a different location.

comment:6 Changed 7 years ago by Jacob

milestone: 1.1

Milestone 1.1 deleted

Note: See TracTickets for help on using tickets.
Back to Top