#33826 closed Cleanup/optimization (fixed)
delete_many()/set_many() crashes with empty values on Redis client .
Reported by: | Christos Kopanos | Owned by: | Christos Kopanos |
---|---|---|---|
Component: | Core (Cache system) | Version: | 4.0 |
Severity: | Normal | Keywords: | redis |
Cc: | 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
I am not sure the behavior described below is the intended (in the sense that the code utilizing the cache backend should make sure to place those checks introduced before calling delete_many or set_many, however looking at the Database backend implementation similar checks do exist when calling the delete_many method and since I jumped into this bug using the redis backend a fix is needed I think to address this issue.
Case
If the 2 methods call the underlying redis client DEL and MSET commands with
empty parameters then an exception will be thrown by the redis client:
redis.exceptions.ResponseError: wrong number of arguments for 'del' command
and
redis.exceptions.ResponseError: Command # 1 (MSET) of pipeline caused error: wrong number of arguments for 'mset' command
respectively.
Steps to reproduce
Using
USE_TZ = False DATABASES = {"default": {"ENGINE": "django.db.backends.sqlite3", "NAME": "mydatabase"}} CACHES = { "default": { "BACKEND": "django.core.cache.backends.redis.RedisCache", "LOCATION": "redis://localhost:6379", } }
as a settings file run a shell
./manage.py shell --settings myapp.settings from django.core.cache import cache cache.delete_many([])
raises exception redis.exceptions.ResponseError: wrong number of arguments for 'del' command
cache.set_many({})
raises exception redis.exceptions.ResponseError: Command # 1 (MSET) of pipeline caused error: wrong number of arguments for 'mset' command
Change History (6)
comment:1 by , 2 years ago
Owner: | set to |
---|
comment:2 by , 2 years ago
Keywords: | redis added |
---|---|
Patch needs improvement: | set |
Summary: | Redis client raises exceptions in the RedisCache backend delete_many and set_many methods when used with empty keys or data → delete_many()/set_many() crashes with empty values on Redis client . |
Triage Stage: | Unreviewed → Accepted |
Type: | Bug → Cleanup/optimization |
comment:3 by , 2 years ago
Patch needs improvement: | unset |
---|---|
Triage Stage: | Accepted → Ready for checkin |
comment:5 by , 21 months ago
I think there's benefit to backporting this change since other cache backends handle this. Trying to convert from django-redis-cache
to Django core's Redis cache is difficult because any number of libraries may be built with this expectation.
comment:6 by , 21 months ago
Ack, never mind. It's pretty easy to subclass the backend and override the two functions to confirm that keys is truthy.
Thanks for the report.