django-environ icon indicating copy to clipboard operation
django-environ copied to clipboard

django-environ doesn't parse redis unix socket location properly

Open emorozov opened this issue 5 years ago • 2 comments

Cache connection string CACHE_URL="rediscache:///var/run/redis/redis-server.sock?db=3&client_class=django_redis.client.DefaultClient"

is incorrectly parsed as:

{'default': {'BACKEND': 'django_redis.cache.RedisCache',
  'LOCATION': 'unix:///var/run/redis/redis-server.sock',
  'OPTIONS': {'DB': 3, 'CLIENT_CLASS': 'django_redis.client.DefaultClient'}}}

DB shouldn't go into OPTIONS, it should be appeneded to the unix socket url: unix:///var/run/redis/redis-server.sock?db=3

Because django-environ doesn't report an error, this can have a very dangerous consequences: you can use redis cache for months only to discover that it always used the default first db instead. Potentially this can lead to data loss.

emorozov avatar May 10 '19 04:05 emorozov

CACHE_URL parsing does not seem to support quoted values (at least not when quoted with ' ) So this maybe works unless there are other issues as well:

CACHE_URL=rediscache:///var/run/redis/redis-server.sock?db=3&client_class=django_redis.client.DefaultClient

thomasf avatar May 25 '19 15:05 thomasf

@thomasf As far as I remember the problem is not in quoting. Problem is somewhere either in django-environ or django-redis. One of the packages or both do not properly handle specifying db when using Unix socketsfor cache. This is probably why the problem went unnoticed - it's very hard to notice that your cache values are stored in a different redis db unless you run several instances of the same app on a single server (my case).

I've tried to find and fix the problem but after wasting three hours just reverted back to using TCP sockets.

emorozov avatar May 27 '19 05:05 emorozov