Opened 2 years ago

Closed 2 years ago

Last modified 20 months ago

#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 Christos Kopanos, 2 years ago

Owner: set to Christos Kopanos

comment:2 by Mariusz Felisiak, 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 datadelete_many()/set_many() crashes with empty values on Redis client .
Triage Stage: UnreviewedAccepted
Type: BugCleanup/optimization

Thanks for the report.

comment:3 by Mariusz Felisiak, 2 years ago

Patch needs improvement: unset
Triage Stage: AcceptedReady for checkin

comment:4 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 608ab043:

Fixed #33826 -- Fixed RedisCache.set_many()/delete_many() crash with an empty list.

comment:5 by Timothy Schilling, 20 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 Timothy Schilling, 20 months ago

Ack, never mind. It's pretty easy to subclass the backend and override the two functions to confirm that keys is truthy.

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