Skip to content

Commit c2e9a28

Browse files
committed
fix JSON serializer and tests with redis-py 6.0
x-ref: redis/redis-py#3622
1 parent aba2916 commit c2e9a28

File tree

2 files changed

+30
-8
lines changed

2 files changed

+30
-8
lines changed

django_rq/tests/utils.py

+27-6
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,36 @@ def get_queue_index(name='default'):
55
"""
66
Returns the position of Queue for the named queue in QUEUES_LIST
77
"""
8-
queue_index = None
98
connection = get_connection(name)
10-
connection_kwargs = connection.connection_pool.connection_kwargs
9+
connection_kwargs = dict(connection.connection_pool.connection_kwargs)
10+
11+
special_case_retry = False
12+
if (retry := connection_kwargs.get('retry')) and retry.__class__.__eq__ == object.__eq__:
13+
special_case_retry = True
14+
del connection_kwargs['retry']
15+
1116
for i in range(0, 100):
1217
try:
1318
q = get_queue_by_index(i)
1419
except AttributeError:
1520
continue
16-
if q.name == name and q.connection.connection_pool.connection_kwargs == connection_kwargs:
17-
queue_index = i
18-
break
19-
return queue_index
21+
if q.name == name:
22+
# assert that the connection is correct
23+
if special_case_retry:
24+
q_connection_kwargs = dict(q.connection.connection_pool.connection_kwargs)
25+
q_retry = q_connection_kwargs.pop('retry', None)
26+
assert q_connection_kwargs == q_connection_kwargs
27+
assert retry # for mypy
28+
assert (
29+
q_retry.__class__ == retry.__class__
30+
and q_retry._retries == retry._retries
31+
and set(q_retry._supported_errors) == set(retry._supported_errors)
32+
and q_retry._backoff.__class__ == retry._backoff.__class__
33+
and q_retry._backoff.__dict__ == retry._backoff.__dict__
34+
)
35+
else:
36+
assert q.connection.connection_pool.connection_kwargs == connection_kwargs
37+
38+
return i
39+
40+
return None

django_rq/utils.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,10 @@ def get_statistics(run_maintenance_tasks=False):
6767
else:
6868
oldest_job_timestamp = "-"
6969

70-
# parse_class and connection_pool are not needed and not JSON serializable
71-
connection_kwargs.pop('parser_class', None)
70+
# remove unneeded properties which are not serializable in JSON
7271
connection_kwargs.pop('connection_pool', None)
72+
connection_kwargs.pop('parser_class', None)
73+
connection_kwargs.pop('retry', None)
7374

7475
queue_data = {
7576
'name': queue.name,

0 commit comments

Comments
 (0)