Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
emorozov opened this issue May 10, 2019 · 2 comments
Open

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

emorozov opened this issue May 10, 2019 · 2 comments
Labels
bug Something isn't working

Comments

@emorozov
Copy link

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.

@thomasf
Copy link

thomasf commented May 25, 2019

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

@emorozov
Copy link
Author

@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.

@joke2k joke2k added the bug Something isn't working label Jul 12, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants