From 6d886d7c7b405c0fe5d59ca192c87b438bf080f5 Mon Sep 17 00:00:00 2001 From: shacharPash <93581407+shacharPash@users.noreply.github.com> Date: Tue, 28 Mar 2023 16:10:25 +0300 Subject: [PATCH] Fix issue 2660: PytestUnraisableExceptionWarning from asycio client (#2669) --- redis/asyncio/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 9e16ee08de..5de2ff960c 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -702,6 +702,11 @@ async def reset(self): self.pending_unsubscribe_patterns = set() def close(self) -> Awaitable[NoReturn]: + # In case a connection property does not yet exist + # (due to a crash earlier in the Redis() constructor), return + # immediately as there is nothing to clean-up. + if not hasattr(self, "connection"): + return return self.reset() async def on_connect(self, connection: Connection):