Skip to content

Commit a081173

Browse files
advance512dvora-h
andauthored
Fix: avoiding issue with PytestUnraisableExceptionWarning (#1458)
* 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'} * linters * linters Co-authored-by: dvora-h <[email protected]>
1 parent 934c689 commit a081173

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

redis/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1151,6 +1151,12 @@ def __del__(self):
11511151
self.close()
11521152

11531153
def close(self):
1154+
# In case a connection property does not yet exist
1155+
# (due to a crash earlier in the Redis() constructor), return
1156+
# immediately as there is nothing to clean-up.
1157+
if not hasattr(self, "connection"):
1158+
return
1159+
11541160
conn = self.connection
11551161
if conn:
11561162
self.connection = None

0 commit comments

Comments
 (0)