#25840 closed Bug (fixed)
cache.get_or_set() works incorrectly with DummyCache backend
| Reported by: | Oleksiy Ivanenko | Owned by: | nobody |
|---|---|---|---|
| Component: | Core (Cache system) | Version: | 1.9 |
| Severity: | Normal | Keywords: | get_or_set dummycache |
| Cc: | oleksiy.ivanenko@… | Triage Stage: | Accepted |
| Has patch: | yes | Needs documentation: | no |
| Needs tests: | no | Patch needs improvement: | no |
| Easy pickings: | no | UI/UX: | no |
Description
There is some issue when you use django.core.cache.cache.get_or_set with DummyCache backend.
from django.core.cache import cache
cache.get_or_set('some_key', 'my_val') # Always returns None. Not a default value
This thing brakes tests.
I think it will be better to return default value from dummy cache.
Attachments (1)
Change History (8)
by , 10 years ago
| Attachment: | get_or_set_dummycache.path added |
|---|
comment:1 by , 10 years ago
| Needs tests: | set |
|---|---|
| Summary: | cache.get_or_set works incorrectly with DummyCache backend → cache.get_or_set() works incorrectly with DummyCache backend |
| Triage Stage: | Unreviewed → Accepted |
comment:2 by , 10 years ago
one might argue that this is a bug in the BaseCache implementation of get_or_set:
def get_or_set(...)
# [snip]
val = self.add(key, default, timeout=timeout, version=version)
if val:
# unlikely, but we might have been added, and evicted again by the time we get here,
# should we not call `get` with the default?
return self.get(key, version=version)
comment:3 by , 10 years ago
My solution provided as PR - https://github.com/django/django/pull/5751
comment:4 by , 10 years ago
Missed the above PR, but here is my approach. (different solution)
Version 0, edited 10 years ago by (next)
comment:5 by , 10 years ago
| Needs tests: | unset |
|---|
Note:
See TracTickets
for help on using tickets.
A regression test is also required. If you can submit your patch as a pull request, that's ideal. Thanks!