Skip to content

Commit 8682814

Browse files
committed
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'}
1 parent 1a41cfd commit 8682814

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

redis/client.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -923,6 +923,11 @@ def __del__(self):
923923
self.close()
924924

925925
def close(self):
926+
# In case a connection property does not yet exist (due to a crash earlier in the Redis() constructor), return
927+
# immediately as there is nothing to clean-up.
928+
if not hasattr(self, 'connection'):
929+
return
930+
926931
conn = self.connection
927932
if conn:
928933
self.connection = None

0 commit comments

Comments
 (0)