Skip to content

Commit

Permalink
Fix: avoiding issue with PytestUnraisableExceptionWarning (#1458)
Browse files Browse the repository at this point in the history
* 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 <67596500+dvora-h@users.noreply.github.com>
  • Loading branch information
advance512 and dvora-h committed Mar 14, 2022
1 parent 934c689 commit a081173
Showing 1 changed file with 6 additions and 0 deletions.
6 changes: 6 additions & 0 deletions redis/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,12 @@ 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
Expand Down

0 comments on commit a081173

Please sign in to comment.