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`.
main
Jochen Kupperschmidt 4 years ago committed by GitHub
parent aa5dbf4af3
commit 617b18a496
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@ import traceback
from datetime import datetime from datetime import datetime
from multiprocessing import Process 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 .defaults import DEFAULT_LOGGING_DATE_FORMAT, DEFAULT_LOGGING_FORMAT
from .job import Job from .job import Job
@ -48,6 +48,16 @@ class RQScheduler(object):
connection_class = connection.connection_pool.connection_class connection_class = connection.connection_pool.connection_class
if issubclass(connection_class, SSLConnection): if issubclass(connection_class, SSLConnection):
self._connection_kwargs['ssl'] = True 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._connection = None
self.interval = interval self.interval = interval

Loading…
Cancel
Save