From 276871b1464303cf42ad5111e1fb5a032aa4c82a Mon Sep 17 00:00:00 2001 From: shacharPash Date: Tue, 28 Mar 2023 14:18:38 +0300 Subject: [PATCH] Fix issue 2660: PytestUnraisableExceptionWarning from asycio client --- 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):