joke2k / django-environ

Django-environ allows you to utilize 12factor inspired environment variables to configure your Django application.
https://django-environ.rtfd.org
MIT License
2.96k stars 315 forks source link

Django's RedisCache OPTIONS needs to be lowercase #517

Open jgoret opened 5 months ago

jgoret commented 5 months ago

We're currently moving our django cache and Celery broker to redis with TLS enabled and need to pass the ssl_cert_reqs parameter to the underlying redis connection.

We're using django-environ to get both settings with a code similar to this :

CACHES = {
    "default": environ.cache(var="CACHE_URL", default="locmemcache://unique-snowflake"),
}

CELERY_BROKER_URL = environ.str(
    "CELERY_BROKER_URL",
    default="amqp://rabbit:rabbit@localhost:5672/",
)

And both environments variables are set like this : rediss://<user>:<password>@<hostname>:<port>/<database_number>?ssl_cert_reqs=none

Everything works fine for Celery but for the cache we're getting an exception because all query parameters are forced to uppercase and the standard Django redis cache (and the underlying redis-py lib) await them in lowercase :

TypeError: __init__() got an unexpected keyword argument 'SSL_CERT_REQS'
[...]
  File "redis/client.py", line 1266, in execute_command
    conn = self.connection or pool.get_connection(command_name, **options)
  File "redis/connection.py", line 1456, in get_connection
    connection = self.make_connection()
  File "redis/connection.py", line 1496, in make_connection
    return self.connection_class(**self.connection_kwargs)
  File "redis/connection.py", line 1104, in __init__
    super().__init__(**kwargs)
  File "redis/connection.py", line 960, in __init__
    super().__init__(**kwargs)

I know that the global lowercase options question was discussed in #87 but as django.core.cache.backends.redis.RedisCache is a natively supported cache scheme I think this should correctly handled.