From 132efcf0d911ed46d6d51064879edfc530fbf568 Mon Sep 17 00:00:00 2001 From: William Morrell Date: Wed, 27 May 2020 10:50:12 -0700 Subject: [PATCH] Check aioredis version for deprecated parameter Starting with aioredis 1.3.1, the loop parameter is deprecated when calling create_redis. See aio-libs/aioredis#666 and django/channels_redis#179. When running Python 3.8+ and aioredis 1.3.1+, calls should omit the loop parameter. Otherwise, continue to include the parameter for the older versions that expect it. --- channels_redis/core.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/channels_redis/core.py b/channels_redis/core.py index f4ff59b..d7100a3 100644 --- a/channels_redis/core.py +++ b/channels_redis/core.py @@ -7,6 +7,7 @@ import logging import random import string +import sys import time import types @@ -18,6 +19,8 @@ logger = logging.getLogger(__name__) +AIOREDIS_VERSION = tuple(map(int, aioredis.__version__.split("."))) + def _wrap_close(loop, pool): """ @@ -70,7 +73,11 @@ async def pop(self, loop=None): """ conns, loop = self._ensure_loop(loop) if not conns: - conns.append(await aioredis.create_redis(**self.host, loop=loop)) + if sys.version_info >= (3, 8, 0) and AIOREDIS_VERSION >= (1, 3, 1): + conn = await aioredis.create_redis(**self.host) + else: + conn = await aioredis.create_redis(**self.host, loop=loop) + conns.append(conn) conn = conns.pop() if conn.closed: conn = await self.pop(loop=loop)