From 8682814d27fc56839f1b8940e1d3a10f710e37db Mon Sep 17 00:00:00 2001 From: Alon Diamant Date: Tue, 9 Mar 2021 20:38:08 +0200 Subject: [PATCH 1/3] Fix: avoiding issue with PytestUnraisableExceptionWarning that is raised because of __del__() calling self.close() in Redis class, as the self.connection attribute was not set due to early failure in the Redis() constructor. Example: calling redis.StrictRedis(**connectionInfo) in a constructor, with connectionInfo={'hog':'cat'} --- redis/client.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/redis/client.py b/redis/client.py index 18553b96ec..250312a5f0 100755 --- a/redis/client.py +++ b/redis/client.py @@ -923,6 +923,11 @@ def __del__(self): self.close() def close(self): + # 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 + conn = self.connection if conn: self.connection = None From 8919cd8f5f4201f2f5aab0f41ff8f4f4e69cd74d Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Mon, 14 Mar 2022 11:16:16 +0200 Subject: [PATCH 2/3] linters --- redis/client.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index f460b032af..c572a1ae72 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1149,7 +1149,8 @@ def __del__(self): self.close() def close(self): - # In case a connection property does not yet exist (due to a crash earlier in the Redis() constructor), return + # 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 From f4fff1c31e436806fba65da9c7bd59f43ee0ef80 Mon Sep 17 00:00:00 2001 From: dvora-h <67596500+dvora-h@users.noreply.github.com> Date: Mon, 14 Mar 2022 11:19:26 +0200 Subject: [PATCH 3/3] linters --- redis/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/redis/client.py b/redis/client.py index c572a1ae72..3b142177b4 100755 --- a/redis/client.py +++ b/redis/client.py @@ -1152,7 +1152,7 @@ def close(self): # 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'): + if not hasattr(self, "connection"): return conn = self.connection