From 617b18a4968c6179c60adbecef23d126150ad5f4 Mon Sep 17 00:00:00 2001 From: Jochen Kupperschmidt Date: Tue, 26 Jan 2021 01:19:03 +0100 Subject: [PATCH] Change back `path` connection keyword argument to `unix_socket_path` (#1403) If a UNIX socket path is passed to the constructor of the Redis client, `redis.client.Redis`, the value of keyword argument `unix_socket_path` is passed to the constructor of `UnixDomainSocketConnection` with the key `path`. When RQ's scheduler creates its own Redis connection, it instantiates class `redis.client.Redis` with keyword arguments obtained from the connection pool. If the pooled connection is a `UnixDomainSocketConnection`, its keyword arguments contain `path`, as given on instantiation. This results in a `TypeError: __init__() got an unexpected keyword argument 'path'`. This change renames the key back to `unix_socket_path` before the keyword arguments dictionary is used to instantiate `redis.client.Redis`. --- rq/scheduler.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/rq/scheduler.py b/rq/scheduler.py index a313a16..dfade4c 100644 --- a/rq/scheduler.py +++ b/rq/scheduler.py @@ -6,7 +6,7 @@ import traceback from datetime import datetime from multiprocessing import Process -from redis import Redis, SSLConnection +from redis import Redis, SSLConnection, UnixDomainSocketConnection from .defaults import DEFAULT_LOGGING_DATE_FORMAT, DEFAULT_LOGGING_FORMAT from .job import Job @@ -48,6 +48,16 @@ class RQScheduler(object): connection_class = connection.connection_pool.connection_class if issubclass(connection_class, SSLConnection): self._connection_kwargs['ssl'] = True + if issubclass(connection_class, UnixDomainSocketConnection): + # The connection keyword arguments are obtained from + # `UnixDomainSocketConnection`, which expects `path`, but passed to + # `redis.client.Redis`, which expects `unix_socket_path`, renaming + # the key is necessary. + # `path` is not left in the dictionary as that keyword argument is + # not expected by `redis.client.Redis` and would raise an exception. + self._connection_kwargs['unix_socket_path'] = self._connection_kwargs.pop( + 'path' + ) self._connection = None self.interval = interval