diff --git a/redis/asyncio/client.py b/redis/asyncio/client.py index 3e6626aedf..5fb94b3353 100644 --- a/redis/asyncio/client.py +++ b/redis/asyncio/client.py @@ -455,7 +455,7 @@ async def __aexit__(self, exc_type, exc_value, traceback): _DEL_MESSAGE = "Unclosed Redis client" def __del__(self, _warnings: Any = warnings) -> None: - if self.connection is not None: + if hasattr(self, "connection") and (self.connection is not None): _warnings.warn( f"Unclosed client session {self!r}", ResourceWarning, source=self )