Opened 3 years ago
Last modified 3 years ago
#33361 closed Bug
Redis cache backend doesn't allow storing bool values — at Version 1
Reported by: | Jeremy Lainé | Owned by: | nobody |
---|---|---|---|
Component: | Core (Cache system) | Version: | 4.0 |
Severity: | Release blocker | Keywords: | |
Cc: | Nick Pope, Daniyal Abbasi | Triage Stage: | Ready for checkin |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description (last modified by )
The following code raises an exception: redis.exceptions.DataError: Invalid input of type: 'bool'. Convert to a bytes, string, int or float first.
from django.core.cache import cache cache.set("foo", True)
This contradicts the documentation which states that any data type supported by pickle can be stored to the cache.
The root cause seems to be because instances of int
are special-cased and not send through pickle, but redis-py cannot send booleans to redis:
What was the rationale behind the int
special-case? django-redis
for instance consistently sends all data through pickle.
Change History (1)
comment:1 by , 3 years ago
Cc: | added |
---|---|
Description: | modified (diff) |
Severity: | Normal → Release blocker |
Triage Stage: | Unreviewed → Accepted |
Thanks for report! It should be enough to special-case
bool
, e.g.django/core/cache/backends/redis.py
:Would you like to prepare a patch?
We do this to have better atomicity of
incr()
anddecr()
operations (see discussion).